访问实体框架数据库时出现问题
我创建了一个 Windows 窗体应用程序,它将使用客户端服务器模型来访问数据库。我为实体框架模型创建了一个连接,它可以与以下连接字符串一起正常工作:
connectionString="metadata=res://*/CartonOrderModel.csdl|
res://*/CartonOrderModel.ssdl|
res://*/CartonOrderModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=.\SQLEXPRESS;
AttachDbFilename=E:\Databases\RollMeasurements.mdf;
Integrated Security=True;
Connect Timeout=30;
User Instance=True;
MultipleActiveResultSets=True""
providerName="System.Data.EntityClient"
我想知道当我将其部署在具有中央数据库服务器并且我的应用程序的多个实例将是的客户端环境上时,此连接字符串是否仍然有效从客户端计算机访问它。
我尝试将连接字符串更改为:
connectionString="metadata=res://*/CartonOrderModel.csdl|
res://*/CartonOrderModel.ssdl|
res://*/CartonOrderModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=.\SQLEXPRESS;
Initial Catalog=RollMeasurements;
User ID=sa;
Password=sapassword;
Connect Timeout=30;
User Instance=True;
MultipleActiveResultSets=True""
providerName="System.Data.EntityClient"
但是现在当我运行我的应用程序时,它给了我这个异常:
无法生成 SQL Server 的用户实例。只有一个集成的 连接可以生成一个用户实例。连接将是 已关闭。
请帮我解决这个问题。谢谢!
I've created a windows forms application that would use a client server model for accessing database. I created a connection for Entity Framework Model and it works fine with the following connection string:
connectionString="metadata=res://*/CartonOrderModel.csdl|
res://*/CartonOrderModel.ssdl|
res://*/CartonOrderModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=.\SQLEXPRESS;
AttachDbFilename=E:\Databases\RollMeasurements.mdf;
Integrated Security=True;
Connect Timeout=30;
User Instance=True;
MultipleActiveResultSets=True""
providerName="System.Data.EntityClient"
I wonder if this connection string would still work when i deploy it on client environment which has a central db server and more than one instance of my app would be accessing it from client machines.
I tried changing the connection string to this:
connectionString="metadata=res://*/CartonOrderModel.csdl|
res://*/CartonOrderModel.ssdl|
res://*/CartonOrderModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=.\SQLEXPRESS;
Initial Catalog=RollMeasurements;
User ID=sa;
Password=sapassword;
Connect Timeout=30;
User Instance=True;
MultipleActiveResultSets=True""
providerName="System.Data.EntityClient"
But now when I run my app it gives me this exception:
Failed to generate a user instance of SQL Server. Only an integrated
connection can generate a user instance. The connection will be
closed.
Please help me with this. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您必须删除
User Instance=True
(或明确将其设置为False
)。用户实例是 SQL Express 数据库的本地副本,不适合在具有中央数据库的多用户环境中工作。I think you have to remove
User Instance=True
(or set it toFalse
explicitely). User Instances are local copies of a SQL Express database and not suited for work in a multiuser environment with a central DB.我认为如果你想访问中央服务器,你需要更改Data Source=.\SQLEXPRESS;线路到中央 SQL Server 实例。
英语不是我的母语,所以可能没有正确理解这个问题。
干杯
I think if you want to access to a central server, you need to change the Data Source=.\SQLEXPRESS; line to a central sql server instance.
english is not my mother language so maybe dont understand correctly the question.
Cheers