无法使用最新的 EntityFramework 连接到任何 SQL 实例

发布于 2024-12-02 21:21:54 字数 539 浏览 1 评论 0原文

我刚刚更新了我的 EntityFramework EntityFramework.4.1.10331.0 到 EntityFramework.4.1.10715.0

使用此版本,我无法使用集成安全性或基于 SQL 的身份验证连接到本地计算机或各种远程计算机上的单个数据库实例。

如果我使用旧的 4.1.10331.0 版本,连接仍然可以正常工作。

我收到的具体错误如下,但是我连接到的实例都是默认实例。

发生网络相关或特定于实例的错误 建立与 SQL Server 的连接。找不到服务器或 无法访问。验证实例名称是否正确 SQL Server 配置为允许远程连接。 (提供者:SQL 网络接口,错误:26 - 定位服务器/实例时出错 指定)

基于 My SQL 的身份验证连接字符串如下所示

服务器=本地主机;数据库=数据库名;UID=用户名;PWD=密码;

有没有其他人遇到过这个问题或者有人可以提出可能的原因吗?

I've just updated my EntityFramework from
EntityFramework.4.1.10331.0
to
EntityFramework.4.1.10715.0

With this version I can't connect to a single database instance on my local machine or a variety of remote machines, using either integrated security or SQL based authentication.

Connections still work fine if I use the the old 4.1.10331.0 release.

The specific error I get is below, however the instances I'm connecting to are all default instances.

A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)

My SQL based authentication connection string looks as follows

Server=localhost;Database=dbname;UID=username;PWD=password;

Has anyone else ran across this or can anyone suggest possible causes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

箜明 2024-12-09 21:21:54

确保您的连接字符串指定了 provider 属性:

SERVER=localhost;DATABASE=dbname;USER ID=username;
PASSWORD=password;PROVIDER=System.Data.SqlClient;

Make sure your connection string has the provider attribute specified:

SERVER=localhost;DATABASE=dbname;USER ID=username;
PASSWORD=password;PROVIDER=System.Data.SqlClient;
苍景流年 2024-12-09 21:21:54

我设法让它工作,但我仍然不完全确定其背后的原因是什么。我认为这可能与 Yuck 建议的 Provider 配置有关。

针对 4.1.10331.0 版本,我在 DBContext 上设置连接字符串,如下所示,效果很好。

Context.Database.Connection.ConnectionString = "Server=localhost;Database=dbname;UID=username;PWD=password;"

但是,对于版本 4.1.10715.0,这将导致错误:26 - 定位服务器/实例指定的异常异常。

现在,我将连接字符串传递到上下文的构造函数中,上下文又将其传递到其基本构造函数中。然后一切都按预期正常工作。

public TestContext(string nameOrConnectionString) : base(nameOrConnectionString) {}

...

var context = new TestContext("Server=localhost;Database=dbname;UID=username;PWD=password;")

I managed to get this working however I'm still not totally sure what the reasoning behind it is. I think it may perhaps be related to a Provider configuration as suggested by Yuck.

Against the 4.1.10331.0 build I was setting the connectionstring on the DBContext as follows and it worked fine.

Context.Database.Connection.ConnectionString = "Server=localhost;Database=dbname;UID=username;PWD=password;"

However, against build 4.1.10715.0 this would result in the error: 26 - Error Locating Server/Instance Specified exception.

I now pass the connectionstring into the constructor of my context, which in turn passed that onto its base constructor. Everything then works fine as expected.

public TestContext(string nameOrConnectionString) : base(nameOrConnectionString) {}

...

var context = new TestContext("Server=localhost;Database=dbname;UID=username;PWD=password;")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文