我的本地web.config和生产web.config之间的差异

本文关键字:config web 之间 我的 | 更新日期: 2023-09-27 18:21:35

我收到这个错误消息

应用程序中的连接字符串"MyConnection"配置文件不包含所需的providerName属性"

我读过这个问题连接字符串';MyConnection';在应用程序';的配置文件不包含所需的providerName属性"关于同样的问题。

在我的情况下,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>

我的本地web.config和生产web.config之间的差异

将其用于您的发布配置文件:

<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。