SQL Server Express and VS2010 Web Application .MDF file errors

I installed SQL Server 2008 as well as SQL Server Express 2008 on my new Windows 7 development environment, along with Visual Studio 2010. I could get SQL Server 2008 to work fine, but I could not use Express .MDF databases within sample web application projects without receiving the below error:

Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.

For instance, I was creating an ASP.NET Web Application. When I ran the application and tried to register a new user, I received an error:

I muddled through a lot of discouraging trials that I won't bore you with while I tried to figure out if the problem was due to the "incompatibility patch" needed with SQL Server 2008 and Windows 7, or if it was due to SQL Server Express being installed incorrectly, or VS2010 or arrrgggh! Needless to say a lot of reinstalls of numerous products were made before finding the below forum post (and the fix was so simple!):

http://forums.asp.net/t/1377174.aspx 

Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.

The above post suggested deleting the SQLEXPRESS directory and rebooting, which I did. Note, my path was quite different than the one recommended in the above post. I used file manager to search for "SQLEXPRESS." 

 C:\Users\Nannette\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS

After reboot, I received an entirely different error: 

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: Shared Memory Provider, error: 40 - Could not open a connection to SQL Server)

One of the readers of the above post, suggested the below fix:

Go to: Control Panel -> Administrative Tools -> Services ->

right click on SQL Server (SQLEXPRESS) service then Properties -> Then Goto Logon tab -> Select the Local System Account option ->Apply->OK

Note, in my install of Windows 7, the Administrative Tools doesn't display in the Control Panel, so I had to search for "Admin" from the Control Panel to pull up the Administrative Tools icon. When I got there, my Local System Account was already setup, so that wasn't my problem. 

However, by taking those steps I found the SQL Server Express was set to Automatic but was not started. So I started it.

I then went back to my web application, and I was able to open the ASPNETDB.MDF file within my VS2010 environment, and I was able to run the application and register a new user! No more errors!

[SIGNATURE]

10 Comments

  • I've been having that same error on two machines for years! I can't wait to try the fix. Kept me from exploring MVC (no registering as a user or logging in possible on a new empty site!)

    I KNEW there'd be a simple answer & I wasn't the only person getting that error msg. You've really helped. Thanks.

  • Yea Its working now. Its great. Actually, I was thinking that I have used the Logon to this account, how this framework will automatically come to know about this. Now, I understood that it is working with the help of System Account.

    Thanks a lot

  • I "heard" of the folder deletion trick while searching this problem...but you helped with documenting the folder heirarchy as mine differed from the link too and my foldernames were hidden.
    Thanks Nannette!

  • It worked. Thanks for posting this. I spent more than 3 hours before searching in google for error.

  • You don't actually have to reboot the computer. You can simply stop the "SQL Server (Express)" service, delete the folder, change the logon details, and then start the service back up.

  • I had the same issue, but on windows XP SP3 so my path was the same.
    Since this is at work and that rebooting takes ages, I just stopped all the SQL related services, deleted the folder, and restarted the services I had stopped and bingo!!!! It worked!
    Thanks for your help.
    Olivier

  • Thanks a lot!
    I had the same error, and was wondering how to deal with the SQL Server error (I guessed the reason, but didn't know the cure!)

    Now everything works fine ^^

  • Thanks very much. I've just downloaded the MVC branch and had DB problems. This fixed it for me (I didn't need to reboot).

  • thanks so much, it works! actually I got the error "Could not connect to the database", during testing simple MVC3 application with create a new user.

    I get stucked for 3-4 days, but here help me.

  • Thanks it helps a lot....

    I was wondering why the database file worked when i install VS 2008 and not in VS 2010...

Comments have been disabled for this content.