Yaza Yaza - 1 month ago 11x
SQL Question

ASP.NET Web API database not created in localdb

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?


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": "test@test.com",
  "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.