Error: Failed to generate a user instance of SQL Server

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 11:35:13

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

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.

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.

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

As noted by others, deleting the contents of directory: c:\Users\\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS solved it for me. A note that may help others, on Windows 7, browsing the c:\users\username dir from document browser does not show the the AppData folder which threw me off for a while (as I thought I did not have the AppData dir) until I discovered that it does indeed exist (but does not show in the document browser in Windows 7), you just have to type in the full path name to get to it.

I started getting this error this morning in a test deployment environment. I was using SQL Server Express 2008 and the error I was getting was

"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."

Unsure about what caused it, I followed the instructions in this post and in other post about deleting the "C:\Users\UserName\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS" directory, but to no avail.

What did the trick for me was to change the connection string from

"Data Source=.\SQLExpress;Initial Catalog=DBFilePath;Integrated Security=SSPI;MultipleActiveResultSets=true"

to

"Data Source=.\SQLExpress;Initial Catalog=DBName;Integrated Security=SSPI;MultipleActiveResultSets=true"

I phase this problem with my mdf file in windows form application and i do just restart my computer and my problem is solve.

To fix this, please Open the SQL Server Management Studio Express. In the query editor type this text:

sp_configure 'user instances enabled', 1;
 RECONFIGURE

Run it. Then restart the SQL Server database.

Have you tried to connect to the SQL Server instance by using SQL Management Studio?

If this also doesn't allow you to connect then it could be because the SQL service is not starting correctly.

Verify that the service is running by checking the services in the control panel.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!