访问实体框架数据库时出现问题

发布于 2024-11-29 12:04:30 字数 1614 浏览 7 评论 0原文

我创建了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水中月 2024-12-06 12:04:30

我认为您必须删除 User Instance=True (或明确将其设置为 False)。用户实例是 SQL Express 数据库的本地副本,不适合在具有中央数据库的多用户环境中工作。

I think you have to remove User Instance=True (or set it to False explicitely). User Instances are local copies of a SQL Express database and not suited for work in a multiuser environment with a central DB.

累赘 2024-12-06 12:04:30

我认为如果你想访问中央服务器,你需要更改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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文