Tip #106 Did you know … How to create the aspnetdb.mdf file?

VS2005, VS2008, VS2010 all supports the following ways to create aspnetdb.mdf file:

1. After create Visual Studio website or web application, Click “ASP.NET Configuration” menu item inside Website menu (for website project) or Project menu (for web project).

2. Commandline aspnet_regsql method to create the aspnetdb schema in any SQL database

 

In VS2010 all editions, the default .NET Framework 4.0 ASP.NET Web Site and Web Application template create default website with following connection string in the web.config:

  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

To get the aspnetdb.mdf created on the fly, one can simply Ctrl-F5 to run the web site or web application.  Click “Log In” button to let the ASP.NET Development Server or IIS server process create the aspnetdb.mdf file for you. 

image

Note, if the web site or web application runs as virtual application in IIS server, create the database process may fail depending on the directory accessibility and IIS application pool Identity.  For example, in IIS7, ApplicationPoolIdentity normally does not have permission to create database by default.  Also, ASP.NET web application project might meet SQL express limitation if the project is under the default project location, such as c:\users\[ACCOUNTNAME]\Documents\Visual Studio 20XX problem (detailed KB article here: http://support.microsoft.com/?kbid=2002980)

 

- Xinyang Qiu |Visual Web Developer Team

No Comments