ASP.NET - what is the App_Data folder for?

November 30, 2008 – 8:00 pm

In addition to supporting server databases, Visual Studio 2005 / 2008 also supports local databases in an App_Data folder. Finding a clear answer as to what the folder is for was not easy but my basic understanding is this:

  • The App_Data directory is a secure place to store data files, because the contents of this directory are never served to client requests.
  • It is also the recommended location for XML files and other data stores.
  • SQL Server databases consist of a .mdf and a .ldf file. These should always be moved together.
  • Creating a local SQL Server database requires that you have SQL Server Express installed on your local machine. When you deploy to a different machine, that machine must also have SQL Server Express installed locally.
  • A local file database is attached to SQL Server Express dynamically through the use of a relative path connection string. The relative path ensures that the application can be moved to another location without breaking the connection to the database. A relative-path connection string in a Web application is specified as follows:
    "server=(local)\SQLExpress;AttachDbFileName=|DataDirectory|MyDatabase.mdf;
    Integrated Security=true;User Instance=true"
    
  • NOTE! Because all ASP.NET applications run under the same process account by default, all applications will attach local databases to the same instance of SQL Server Express. This means that all applications will have equal access to all attached databases in this instance, regardless of the individual application that attached a database initially. For isolation between applications using SQL Server Express, you must run each application is a separate worker process or application pool (under IIS 6). For this reason, local SQL Server databases are considered more of a development-time convenience, and not an replacement for server-based databases in shared hosting scenarios.

More info:
http://msdn.microsoft.com/en-us/library/8fxztkff.aspx

Your Ad Here

Post a Comment