Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Failed to generate a user instance of SQL Server

I'm trying to connect to an MDF. I've even gone to the lengths of re-installing sql server express entirely (it is now the only flavor of SQL installed on my box, where previously I had 05 dev and express). I've verified that the paths are all correct, and thus far my google-fu hasn't helped.

The Full exception 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.

The Connection string is:

<add name= "CustomerEntities"
     connectionString="metadata=res://*/Data.CustomerModel.csdl|res://*/Data.CustomerModel.ssdl|res://*/Data.CustomerModel.msl;
     provider=System.Data.SqlClient;
     provider connection string='Data Source=.\SQLEXPRESS;
     AttachDbFilename=\App_Data\CustomerDb.mdf;
     Integrated Security=True;
     User Instance=True'"
     providerName="System.Data.EntityClient" />

Additional info:

Several of the references to this error I've found online do not apply to me. For example, one I've seen is where this error occurs when trying to start the user instance over remote desktop (I'm doing this locally). While another suggests that it has to do with leftover files from an old express installation ... I've looked in the prescribed locations and not found those artifacts. I also tried running sp_configure 'user instances enabled', '1', but it said that it was already set to 1.

like image 305
Joel Martinez Avatar asked Nov 11 '08 17:11

Joel Martinez


4 Answers

ok, it works now! guess it was a compound problem ... the steps I took to resolve it are as such:

  1. Changed the following property in the connection string (note the subtle difference): AttachDbFilename=|DataDirectory|CustomerDb.mdf;
  2. Deleted the contents of the following directory: c:\Users\<user name>\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS. I thought I had looked for this before, but I had actually looked in the Microsoft Sql Server folder. Again, a subtle difference.

Once I did these two things, the connection started working :-D

like image 107
Joel Martinez Avatar answered Oct 01 '22 01:10

Joel Martinez


I experienced the same error when i moved the code from one machine to another. i am using VS2010 and SQLEXPRESS 2008 comes along with it.

Trick , deleting all the contents from the following folde "C:\Users\UserName\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS" worked for me.

like image 21
DSH Avatar answered Sep 30 '22 23:09

DSH


Even despite above answers solved the problem many people, I m still finding these falling short of the essence of the problem. Closest to it is the answer by @sohaiby above. But it wrongly refers to using Management Studio.

The error message on top of this topic tells very clearly that the problem is with generating a user instance. What instance is and how it is used is described here in every detail: https://msdn.microsoft.com/en-us/library/ms254504(v=vs.110).aspx

Personally, I encountered this problem when switching DB connection from windows authentication mode to SQL Server authentication. I solved it by just modifying a part of connection string to: "User Instance=false;" instead of "User Instance=true;", which worked fine with windows authentication.

After I changed to "User Instance=false;" my connection worked fine without any additional manipulations. I cannot insist that it will work or will be suitable in all scenarios. However, I will definitely recommend trying it before other drastic methods described above, such as erasing SQL server work directories.

like image 5
Boris Zinchenko Avatar answered Oct 01 '22 01:10

Boris Zinchenko


In addition to the other solutions here, this one may also be helpful. Ensure the Application Pool is running as network service, and not ApplicationPoolIdentity.

This solution was found here: http://blogs.msdn.com/b/webdevelopertips/archive/2010/05/06/tip-106-did-you-know-how-to-create-the-aspnetdb-mdf-file.aspx

like image 1
Derrick Avatar answered Sep 30 '22 23:09

Derrick