.net 实体框架:需要连接字符串中的“ProviderName” - 突然之间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18619848/
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
Entity Framework: "ProviderName" in connection string required- all of the sudden?
提问by esmoore68
We've been using Entity framework in a production environment for many months now, and just yesterday started to get errors on somemachines when querying the database using our subclass of DbContext:
我们已经在生产环境中使用实体框架好几个月了,就在昨天,当使用我们的 DbContext 子类查询数据库时,一些机器开始出现错误:
"The connection string 'MyConnectionString' in the application's configuration file does not contain the required providerName attribute"
“应用程序配置文件中的连接字符串‘MyConnectionString’不包含所需的 providerName 属性”
Our problem is easily solved: I adding the "providerName="System.Data.SqlClient"to the connection string in the config files on all deployed servers and workstations.
我们的问题很容易解决:我"providerName="System.Data.SqlClient"在所有部署的服务器和工作站上的配置文件中添加了连接字符串。
However, the mystery remains: according to the documentation:
然而,谜团仍然存在:根据文档:
The providerName attribute is optional, and the default is "System.Data.SqlClient".
providerName 属性是可选的,默认为“System.Data.SqlClient”。
Even more mysterious is why this started happening suddenly, and apparently only on some machines. I am not aware of any recent changes in EF or .NET versions, any SQL Server version or provider changes, or anything. But I realize there has to be something I've overlooked.
更神秘的是为什么这突然发生,而且显然只在某些机器上发生。我不知道 EF 或 .NET 版本的任何最近更改、任何 SQL Server 版本或提供程序更改或任何内容。但我意识到一定有一些我忽略了的东西。
.NET 4.5 EF 5.0
.NET 4.5 英孚 5.0
Anyone have any hints or insights?
任何人有任何提示或见解?
采纳答案by Jon Adams
Certain driver combinations will cause the machine to be in a state where it is ambiguous which driver it should use, so it requires an explicit provider name.
某些驱动程序组合会导致机器处于不明确应该使用哪个驱动程序的状态,因此它需要一个明确的提供程序名称。
It was probably some other separate application or driver install, or automatic Windows Update that ran.
可能是其他一些单独的应用程序或驱动程序安装,或者运行的自动 Windows 更新。
Being explicit with the provider name doesn't hurt anything though. You should be fine adding it; it's only a few extra characters in your connection string. It won't ever need to change in the future or anything.
但是,明确提供提供者名称并没有什么坏处。添加它应该没问题;它只是您的连接字符串中的几个额外字符。它在未来或任何事情都不需要改变。
Your updated declaration should read:
您更新后的声明应为:
<connectionStrings>
<add
name="MyConnectionStringName"
connectionString="Connection string goes here"
providerName="System.Data.SqlClient" />
</connectionStrings>
回答by Diego Venancio
You can use too:
您也可以使用:
providerName="System.Data.EntityClient"
then:
然后:
<add name="name_here" connectionString="Data Source="pathofdatabase" providerName="System.Data.EntityClient" />

