我收到此错误消息
连接字符串' MyConnection'在应用程序中 配置文件不包含必需的providerName 属性"
关于同样的问题,我读了这个问题The connection string 'MyConnection' in the application's configuration file does not contain the required providerName attribute."。
在我的例子中,providerName =" System.Data.SqlClient"正确地在我的本地web.config文件中,但是当我在我的生产服务器上发布(在发布版本中)时,它会消失。我的本地服务器上没有问题。
修改
这是我的发布配置文件
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
答案 0 :(得分:0)
将此用于您的发布配置文件:
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" providerName="System.Data.SqlClient" />
</connectionStrings>
本地的ConnectionString正在由发布配置文件进行更改。因此,如果您在本地配置中声明providerName,那么在发布发布文件时将无用。您还需要在发布配置文件中声明providerName。