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
Asked Answered
M

6

21

I've attempted to add a "service based data base" (.mdf) to a project in an asp .net application. From there I've proceeded attempted to create an entity framework model file (.edmx).

When doing so I get the error:

An error occurred while connecting to the database. The database might be unavailable. An exception of type 'System.Data.SqlClient.SqlException' occurred. The error message is: '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've got SQL Server 2008 R2 Express edition installed on my machine.

Any ideas would be most appreciated.

Management answered 11/9, 2011 at 2:1 Comment(3)
What does your connection String look like?Housekeeper
#7382091Management
What worked for me was the answer i gave in the link above ^Management
M
43

I have got the same error, it's fixed after the following change.

Deleting the folder C:\Users\User\AppData\Local\Microsoft\Microsoft SQL Server Data worked for me in Windows 7. Have to restart VS after deleting the folder.

Moreta answered 4/1, 2013 at 9:47 Comment(4)
Worked for me immediately even without a restart.Botulin
I had copied my AppData from another machine, presumably causing the issue in the first place. Thanks!Scornik
I'm running VS2013 and SQL Server 2014 Express and deleting the folder did not help me.Flatling
Happened for me after removing SQL Server Express, then re-installing. Nice one, thanks!Dufresne
H
4

See this answer, which might work for you.

Based on your connection string, you might need to add "User Instance" attribute to it.

Housekeeper answered 11/9, 2011 at 2:19 Comment(0)
P
4

I had this exact same problem with a C# Console App that was utilizing an .mdf file.

The issue disappeared once I granted NETWORK SERVICE full access to my root-level Visual Studio project directory (and sub directories).

Solution Details: Problems with SQL Server Express user instancing and ASP.net Web Application Projects

Pylorus answered 12/9, 2012 at 1:56 Comment(0)
T
1

I was facing same issue in VS 2019. if anyone still facing same issue then please make sure you have/do following things: 1. you should have Sql server Express installed on your m/c 2. should have SSDT installed in VS (in VS 2019- name sure to check this component while installing) for previous version; i guess you have to add this externally 3. add 'User Instance = True' to your connection string and one more thing and I think its optional - open VS and SQL in administrative mode

Ty answered 10/2, 2020 at 17:21 Comment(0)
S
0

If you build your own custom membership solution, do not forget to add this line to your Web.config's AppSettings section:

<add key="enableSimpleMembership" value="false" />

otherwise you'll get the same error message

Shaker answered 7/12, 2020 at 22:55 Comment(0)
M
0

I have same issue, but it only happens when I reboot the PC and run the application from a fresh start. If I then attempt to re-start the application (wo rebooting), it does connect and I have full access to the database. I tried to change the connection string with a long timeout (600, 6000, 60000), but that made no difference. Here is the connection string: " "

Mcdowell answered 20/8, 2021 at 23:32 Comment(3)
What have you tried to let the first run succeed ? Have you tried the answers here ? Just stating you have the same issue is no answer.. rather a Comment..Kana
I indicated that I tried changing the Connection Timeout values, but that did not help.Mcdowell
I also should add, that on fresh boot, sometimes it will create the user instance, and the application works. This happens about 25% of the time that it will work on fresh boot. But 100% of the time when I kill that application and restart again, it will work.Mcdowell

© 2022 - 2024 — McMap. All rights reserved.