Why is the mdf file not showing up in the App_Data folder?

I am trying to start from the beginning of ASP.NET MVC 4.

And immediately hit the problem, according to the e-book, I would have to start a new mvc 4 internet application, debug and select the log-in from tempate UI, and then stop. This should create the mdf file in the App_Data folder. Which I should be able to click and open in Server Explorer.

What actually happens is the database is created in my SQL Express.

The correct execution of this step is critical to the rest of the tutorial.

I am familiar with MVC, but mostly with the interface, so I am trying to improve my understanding of the database side / MVC models.

This is a completely new project, no changes have been made, only from the box code. On a Windows XP machine using Visual Studio 2010.

Connectionstring -

<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-HaveYouSeenMe-20131125091100;Integrated Security=SSPI" providerName="System.Data.SqlClient" /> 

Can someone explain why my connectionstring from the line creates Db in SQL Express and how to create mdf in the App_Data folder, as the book suggests. amuses.

+7
c # visual-studio-2010 asp.net-mvc-4
source share
7 answers

Just change the connection string:

 <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnet-HaveYouSeenMe-20131125091100.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/> 

|DataDirectory| is a special token pointing to the ~/App_Data your application.

Check out the following article on MSDN , which contains more information about connection strings in SQLExpress.

+4
source share

I know this answers, but it can be as simple as clicking the "show all files" icon in Solution Explorer. By default, the .mdf file will not be displayed, so be sure to select "show all files" :)

+19
source share

It took me a while to figure this out, since I want to attach the database under App_Data, and nothing happens. No files added. I just understand that there are two options for clicking Show all files.

In this picture, I clicked the arrow Red , which said Show all files. After some time, I tried to click another Show all files on the blue arrow, and now it works. enter image description here

I hope this can help if you come across the same problem.

+1
source share

The database was most likely created in the Documents folder. In Server Explorer, right-click the database (in data connections) and select Browse in SQL Server Object Explorer. Then, in the SQL Object Browser, right-click the database and select Properties. In the Properties window, find “Current Connection Settings” and see Value for the data file.

To ensure that the database is created in the App_Data folder, insert AttachDbFilename=|DataDirectory|\database_name.mdf in the connection string.

+1
source share

You are missing AttachDbFilename

  <connectionstrings> <add connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnet-HaveYouSeenMe-20131125091100.mdf;Integrated Security=True;User Instance=True " name="ConnectionASPX" providername="System.Data.SqlClient" /> </connectionstrings> 

Instead of the physical path to the database file stored in the App_Data folder, you can specify the |DataDirectory| in setting AttachDbFilename .

0
source share

In my case, this is because the user account that I use to log into my computer is a Microsoft account (Outlook email address), and Visual Studio reads my local user account. The local user account is "userName" in C: \ Users \ userName \ Documents \ Visual Studio 2015 \ Projects \ ProjectFolder \ App_Data.

I am using Visual Studio 2015 on Windows 10.

The solution is simple. I just need to go into the settings of my PC, select "Accounts" and choose to enter the local account instead of the Microsoft account.

0
source share

You can also go into the server explorer and right-click on the data connections . Then click “add connections” and change the source “server database file and under the name of the database file (new or existing) you go to the app_data folder if you cannot find the .mdf file, then go to this folder and add the name that You want to provide your file.

 `SulemansStore\SulemansStore\App_Data\SulemansDatabase.mdf` 

I look through App_Data and add the name of my Sulemansdatabase.mdf database Sulemansdatabase.mdf (I added this part if I create a new database file).

0
source share

All Articles