visual-studio 错误:无法生成 SQL Server 的用户实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/281500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Failed to generate a user instance of SQL Server
提问by Joel Martinez
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.
我正在尝试连接到 MDF。我什至不遗余力地完全重新安装 sql server express(它现在是我的机器上安装的唯一一种 SQL,以前我有 05 dev 和 express)。我已经验证路径都是正确的,到目前为止我的 google-fu 没有帮助。
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.
由于为用户实例启动进程失败,无法生成 SQL Server 的用户实例。连接将被关闭。
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.
我在网上找到的一些对这个错误的引用不适用于我。例如,我见过的一个是尝试通过远程桌面启动用户实例时发生此错误的地方(我在本地执行此操作)。而另一个建议它与旧的快速安装的剩余文件有关......我已经查看了规定的位置并没有找到那些工件。我也试过运行sp_configure 'user instances enabled', '1',但它说它已经设置为 1。
回答by Joel Martinez
ok, it works now! guess it was a compound problem ... the steps I took to resolve it are as such:
好的,现在可以使用了!我猜这是一个复合问题……我解决它的步骤是这样的:
- Changed the following property in the connection string (note the subtle difference):
AttachDbFilename=|DataDirectory|CustomerDb.mdf; - 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 theMicrosoft Sql Serverfolder. Again, a subtle difference.
- 更改了连接字符串中的以下属性(注意细微差别):
AttachDbFilename=|DataDirectory|CustomerDb.mdf; - 删除了以下目录的内容:
c:\Users\<user name>\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS. 我以为我以前找过这个,但实际上我在Microsoft Sql Server文件夹里找过。再次,细微的差别。
Once I did these two things, the connection started working :-D
一旦我做了这两件事,连接就开始工作了:-D
回答by Boris Zinchenko
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.
尽管以上答案解决了很多人的问题,但我仍然发现这些没有达到问题的本质。最接近它的是上面@sohaiby 的答案。但它错误地指的是使用 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
本主题顶部的错误消息非常清楚地表明问题在于生成用户实例。此处详细描述了实例是什么以及如何使用它: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.
就个人而言,我在将 DB 连接从 Windows 身份验证模式切换到 SQL Server 身份验证时遇到了这个问题。我通过将连接字符串的一部分修改为:“User Instance=false;”来解决它 而不是“User Instance=true;”,它适用于 Windows 身份验证。
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.
在我改为“User Instance=false;”之后 我的连接工作正常,没有任何额外的操作。我不能坚持它会在所有情况下都有效或适用。但是,我肯定会建议在上述其他激烈方法之前尝试它,例如擦除 SQL 服务器工作目录。
回答by DSH
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.
当我将代码从一台机器移动到另一台机器时,我遇到了同样的错误。我正在使用 VS2010 并且 SQLEXPRESS 2008 随之而来。
Trick , deleting all the contents from the following folde "C:\Users\UserName\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS" worked for me.
技巧,删除以下文件夹中的所有内容“C:\Users\UserName\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS”对我有用。
回答by Derrick
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.
除了这里的其他解决方案之外,这个解决方案也可能有帮助。确保应用程序池作为网络服务运行,而不是 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
这个解决方案在这里找到:http: //blogs.msdn.com/b/webdevelopertips/archive/2010/05/06/tip-106-did-you-know-how-to-create-the-aspnetdb-mdf-文件.aspx
回答by Jarnal
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.
正如其他人所指出的,删除目录的内容: c:\Users\\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS 为我解决了这个问题。在 Windows 7 上,从文档浏览器浏览 c:\users\username 目录可能会帮助其他人的注释不会显示 AppData 文件夹,这让我有一段时间(因为我以为我没有 AppData 目录)直到我发现它确实存在(但不显示在 Windows 7 的文档浏览器中),您只需输入完整路径名即可访问它。
回答by Hamid Shahid
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
我今天早上在测试部署环境中开始收到此错误。我使用的是 SQL Server Express 2008,我得到的错误是
"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."
“由于启动用户实例进程失败,无法生成 SQL Server 的用户实例。连接将被关闭。”
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.
不确定是什么原因造成的,我按照这篇文章和其他关于删除“C:\Users\UserName\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS”目录的说明操作,但无济于事。
What did the trick for me was to change the connection string from
对我来说,诀窍是将连接字符串从
"Data Source=.\SQLExpress;Initial Catalog=DBFilePath;Integrated Security=SSPI;MultipleActiveResultSets=true"
“数据源=.\SQLExpress;初始目录=DBFilePath;集成安全性=SSPI;MultipleActiveResultSets=true”
to
到
"Data Source=.\SQLExpress;Initial Catalog=DBName;Integrated Security=SSPI;MultipleActiveResultSets=true"
"Data Source=.\SQLExpress;Initial Catalog=DBName;Integrated Security=SSPI;MultipleActiveResultSets=true"
回答by Kishan
I phase this problem with my mdf file in windows form application and i do just restart my computer and my problem is solve.
我在 Windows 窗体应用程序中用我的 mdf 文件分阶段解决这个问题,我只是重新启动我的计算机,我的问题就解决了。
回答by Harshil Parekh
Just go to web.config file. Change in 'Connection String'="....../.../......?.......; User Instance=True'" to "....../.../......?.......; User Instance=False'"
只需转到 web.config 文件。将 'Connection String'="....../.../......?.......; User Instance= True'" 更改为 "....../. ../......?.......; 用户实例 = False'"
Yes this may cause some security issues, but for some school/college practical-project(Which was my case) this can run your project.
是的,这可能会导致一些安全问题,但是对于某些学校/学院的实践项目(我就是这样),这可以运行您的项目。
change from User Instance=True to User Instance=False ,in web.config
在web.config 中从 User Instance=True 更改为 User Instance=False
回答by sohaiby
To fix this, please Open the SQL Server Management Studio Express. In the query editor type this text:
要解决此问题,请打开 SQL Server Management Studio Express。在查询编辑器中输入以下文本:
sp_configure 'user instances enabled', 1;
RECONFIGURE
Run it. Then restart the SQL Server database.
运行。然后重新启动 SQL Server 数据库。
回答by Jimoc
Have you tried to connect to the SQL Server instance by using SQL Management Studio?
您是否尝试过使用 SQL Management Studio 连接到 SQL Server 实例?
If this also doesn't allow you to connect then it could be because the SQL service is not starting correctly.
如果这也不允许您连接,则可能是因为 SQL 服务未正确启动。
Verify that the service is running by checking the services in the control panel.
通过检查控制面板中的服务来验证服务是否正在运行。

