views:

392

answers:

3

I just installed SQL-Server Express 2005 on my machine and I am trying to create a Service-based Database for a C# application. But when I try to create it I end up with the following error message:

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.

I'm completely new to SQL-Sever and C#, so what do I need to do to fix this problem?
(I'm coming from a MySQL/Java background.)

+18  A: 

Try deleting the files in the "c:\Documents and Settings[user]\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS" folder.

Leroy Jenkins
@DataPimp I'm running Windows 7 and this directory does not exist.
leeand00
Can I ask why you choose to install 2005 instead of 2008?
Leroy Jenkins
Leroy Jenkins
No I don't think I have that installed...hmmm
leeand00
So how was the accepted answer any different that what I posted?
Leroy Jenkins
@DataPimp I found this same answer several other places (notably the Head First C# Forum). I just didn't know what the answer was for Windows 7, it's probably actually a different question (where did they move the "documents and settings" folder to?) I gave you an upvote anyway though. Sorry for the Drama.
leeand00
+1  A: 

If you are using AttachDbFilename attribute in connection string like this:

Data Source=.\SQLEXPRESS;AttachDbFilename=PATH/YOURDB.mdf;Integrated
Security=True;Connect Timeout=30;User Instance=True

then you need to enable user instance in SQL Server 2005 Express edition. Open SQL Server Management Studio Express or SQL Server Console and run following commands:

exec sp_configure 'user instances enabled', 1
reconfigure
TheVillageIdiot
@TheVillageIdiot It said that 'user instances' was changed from 1 to 1, and that I should run the reconfigure command (which I did as a separate query per your example.
leeand00
@TheVillageIdiot Then I got the same error message when I tried to create the Service-based Database again.
leeand00
@leeand00 then there may be something Windows 7 specific problem with this
TheVillageIdiot
A: 

Okay found the solution. Since I was using Windows7 I had to delete that directory from

C:\Users\leeand00\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS instead.

Thanks all!

leeand00
It would have been courteous to give credit (/accepted answer) to DataPimp's answer here; he clearly indicated exactly where the problem was, give or take the users's profile location.
Marc Gravell
@Marc, I found the same answer that Data Pimp gave me (before Data Pimp gave me it), on another website, but it was not Windows 7 specific.
leeand00