.net - Entity Framework : "ProviderName" in connection string required- all of the sudden?

标签 .net entity-framework connection-string

我们已经在生产环境中使用 Entity Framework 好几个月了,就在昨天,当使用我们的 DbContext 子类查询数据库时,一些机器开始出现错误:

"The connection string 'MyConnectionString' in the application's configuration file does not contain the required providerName attribute"



我们的问题很容易解决:我添加了 "providerName="System.Data.SqlClient"到所有部署的服务器和工作站上的配置文件中的连接字符串。

然而,谜团仍然存在:根据the documentation :

The providerName attribute is optional, and the default is "System.Data.SqlClient".



更神秘的是为什么这突然发生,而且显然只在某些机器上发生。我不知道 EF 或 .NET 版本的任何最近更改、任何 SQL Server 版本或提供程序更改或任何内容。但我意识到一定有一些我忽略了的东西。

.NET 4.5
英孚 5.0

任何人有任何提示或见解?

最佳答案

某些驱动程序组合会导致机器处于不明确应该使用哪个驱动程序的状态,因此它需要一个明确的提供程序名称。

可能是其他一些单独的应用程序或驱动程序安装,或者运行的自动 Windows 更新。

但是,明确提供提供者名称并没有什么坏处。添加它应该没问题;它只是您的连接字符串中的几个额外字符。它在 future 或任何事情都不需要改变。

您更新后的声明应为:

<connectionStrings>
  <add
    name="MyConnectionStringName"
    connectionString="Connection string goes here"
    providerName="System.Data.SqlClient" />
</connectionStrings>

关于.net - Entity Framework : "ProviderName" in connection string required- all of the sudden?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18619848/

相关文章:

javascript - 从 Node.js 连接 Azure 分析服务

c# - 如何使用 ScrollBarRenderer 更改滚动条颜色

c# - 弱引用和事件处理

c# - 如何在使用await async期间运行sql查询

entity-framework - 可以广播消息时,消息系统如何组织数据库表?

asp.net-mvc - EntityFramework 到 Json 的解决方法? (在序列化 ...DynamicProxies 类型的对象时检测到循环引用)

c# - MySQL 连接字符串 "No Database Selected"

c# - MVC 构建 - 根据构建配置编辑连接字符串文件 (VS2012)

c# - 捕捉 HttpException 是个好主意?

.net - 使用 LetsEncrypt.org SSL 证书签署 Visual Studio 应用程序