C# 我的本地web.config和生产web.config之间的差异
我收到了这个错误消息 应用程序中的连接字符串“MyConnection” 配置文件不包含所需的providerName 属性。” 我读到这个问题是关于同一个问题的 在我的例子中,providerName=“System.Data.SqlClient”正确地位于本地的web.config文件中,但在我的生产服务器(内置版本)上发布时消失。我的本地服务器上没有问题 编辑 这是我的发布配置文件C# 我的本地web.config和生产web.config之间的差异,c#,asp.net,.net,C#,Asp.net,.net,我收到了这个错误消息 应用程序中的连接字符串“MyConnection” 配置文件不包含所需的providerName 属性。” 我读到这个问题是关于同一个问题的 在我的例子中,providerName=“System.Data.SqlClient”正确地位于本地的web.config文件中,但在我的生产服务器(内置版本)上发布时消失。我的本地服务器上没有问题 编辑 这是我的发布配置文件 <?xml version="1.0" encoding="utf-8"?> <!--
<?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>
将其用于发布配置文件:
<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。最有可能由web.config转换引起检查web.release.configWhen中的内容发布后,将应用任何配置转换。检查您的解决方案中是否有类似Web.Config.Production的内容。发布过程会重写连接字符串。您是否在“发布”的“设置”部分设置了连接字符串“对话框?通常,您不会用开发人员计算机上的生成或发布过程发布的文件覆盖生产服务器上的
web.config
文件。您只需根据该服务器上的设置对其进行编辑。在这种情况下,请手动编辑该文件以包含您的提供者名称
@AlexBarac:您似乎需要从VisualStudio和msdeploy中了解很多关于“发布”的信息。Visual Studio允许您根据vs中选定的解决方案配置将转换应用于web.config,这样就无需对部署到服务器上的文件进行任何手动编辑。