When creating a new database with SQL Server Express 2005, the database files (.mdf and .ldf) get stored in C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data
by default.
However, with the tutorials I've seen for ASP.NET MVC (e.g., Nerd Dinner), it seems to be common practice to keep the database files in the ASP.NET project's App_Data folder.
Questions
Update
One thing I'm still not getting. If you have a production database on the server, why would you even want to replace this database with what is in App_Data. Wouldn't you normally just want to have update scripts that you run on the production database when you release a new version of the app? Even for initial deployment, I'd rather script database creation than physically copy over the files. Also, with SQL Server (Express) databases, copying is not enough. You have to detach the database to manipulate the files then reattach when you are done.
So, I have to say, the point of App_Data still escapes me. Can someone enlighten me?
The App_Data folder of MVC application is used to contain the application related data files like . mdf files, LocalDB, and XML files, etc. The most important point that you need to remember is that IIS is never going to serve files from this App_Data folder.
App_Data contains application data files including . mdf database files, XML files, and other data store files. The App_Data folder is used by ASP.NET to store an application's local database, such as the database for maintaining membership and role information.
Select “ Web application (Model-View-Controller)” template and press OK to create Asp.Net Core MVC project. Right-click on the solution and add a new folder named “Models”. Now, add a new class on the Models folder. Right-click on Models folder and select "Add a new class".
You can delete App_Data without any negative repercussions, but when it exists (by folder name) inside an ASP.NET website then it has the special website power of disallowing direct linking to download its contents - this is a security feature to protect your database from being downloaded directly over the web (e.g. by a web browser) even though it exists in the website. However your application can still access the files in the App_Data folder just as it accesses other website content.
Microsoft states it as:
Note: The content of application folders, except for the App_Themes folder, is not served in response to Web requests, but it can be accessed from application code.
Microsoft describes their special ASP.NET folder structures including App_Data here.
There are a number of advantages of placing database files in the App_Data
folder:
There is absolutely no need to use the App_Data folder. It's just a convenient place to keep your database files together with your site. The decision to use it or not is more a matter of preference / policy than anything else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With