Hook an ASP.NET MVC 2 Web Application into an existing SQL Server 2008 R2 instance

I was revisiting project templates in VisualStudio 2010 and when I was playing around I created an ASP.NET MVC 2 Web Application. I then wanted to hook into my existing SQL Server 2008 R2 instance rather than the SQLEXPRESS instance (the default the project template is setup to use) because I was getting this error:
“Unable to connect to SQL Server database.”
“A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)”

This was because the SQLEXPRESS instance was disabled, of course I enabled it and then it created the ASPNETDB.MDF in the App_Data folder and registered a new user just fine. But I didn’t want this, I wanted a “real” DB to play about with so I disabled the SQLEXPRESS instance again and deleted the ASPNETDB.MDF file.
I changed the default connection string from:
“data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true”
to:
“Data Source=localhost;Integrated Security=True;Initial Catalog=aspnetdb;”
Great, but I then needed to create the aspnetdb DB, but that was easy, I used aspnet_regsql.exe (ASP.NET SQL Server Setup Wizard). You can configure the name you want for your database (aspnetdb in my case) in the wizard or the application takes command line arguments too.
I then had a “real” DB I could play about with in Management Studio without attaching the ASPNETDB.MDF or any other fiddling about.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s