3

I have created an asp.net web api 4.5.2 project and I can't find the database that it's using for adding users. The info in the connection string:

Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplicationTest2-20160906022916.mdf;Initial Catalog=aspnet-WebApplicationTest2-20160906022916;Integrated Security=True. 

But when I check the app_data directory it's empty. Where can I find this database?

2 Answers 2

7

Database creation for templates are delayed until a request is sent.

Run your server and POST following JSON with Content-Type: application/json header to http://localhost:xxx/api/Account/Register:

{
  "Email": "[email protected]",
  "Password": "TestTest1!",
  "ConfirmPassword": "TestTest1!"
}

You should get 200: OK.

I am using Advanced REST client.

Advanced REST Client Chrome

After that database will be created in App_Data folder. If server returned 200: OK and App_Data is empty, Do the following steps:

In Visual Studio go to View menu. Select SQL Server Object Explorer(or press Ctrl+\, Ctrl+S).

Your SQL server should be there. You can find your database in Databases folder.

Visual Studio View menu SQL Server Object Explorer

If you need specifically the data file, then expand Databases folder, right click on which one you need and click on Properties. Scroll down to see Current Connection Parameters.

Properties

Sign up to request clarification or add additional context in comments.

7 Comments

Hi Orkhan, thank you for your answer. I checked the database as you suggested. The problem is that I don't see the database there? It looks like it doesn't exists. When I try to connect to it, the database server tells me that it can't attache the file. Is there a way to generate this database through scripts?
Right click on database server starting with (localdb)\MSSQLLocalDb... and choose New Query, write create database MyDatabase, then execute. You'll need to refresh Server Object Explorer to see created database. To get connection string to newly created database, rightclick on it and open up Properties window, there you will see Connection String of that database
Or right click on Databases click Add New Database
Well I know how to create a database. I ment what's the database model of the database used in api? How can I generate the database to be ready to use for the api.
Did you created an empty project or a template? For an empty project, you have to create nothing until you need.
|
0

Some times this error occurred when you do not install local db of SQL server.To know if you install local db,open command prompt(administrator) and type "SqlLocalDb info".Then it show localdb name.add that name into connection string.If command prompt is not show this,refer following link to add localdb into SQL express server. link:-https://www.mssqltips.com/sqlservertip/5612/getting-started-with-sql-server-2017-express-localdb/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.