首页 > 解决方案 > 发布时在服务器上更新连接字符串

问题描述

我正在尝试在发布期间在生产服务器上更新我的连接字符串值。我正在尝试以下没有结果:

<connectionStrings>
add name="DataConnect" connectionString="Server=Pepe;Database=Oyeti;Integrated Security=SSPI;" xdt:Transform="Replace" />

并且还添加了 xdt:Locator,但我认为这不是正确的方法:

<connectionStrings>
add name="DataConnect" connectionString="Server=Pepe;Database=Oyeti;Integrated Security=SSPI;" xdt:Transform="Replace" xdt:Locator="Match(name)" />

我在那里看不到什么?

谢谢!

标签: c#asp.netpublish

解决方案


您可以将xdt:Transform="SetAttributes" xdt:Locator="Match(name)属性添加到转换文件 (Web.Release.config) 中的 connectionString 标记,以转换主配置文件 (Web.config) 中的值。作为替代方案,您还可以在发布配置文件中指定连接字符串。

尽管默认转换文件包含一个显示如何更新连接字符串的示例,但在大多数情况下,您不需要设置连接字符串转换,因为您可以在发布配置文件中指定连接字符串。您将在部署到 IIS 和部署到生产教程中执行此操作。

https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations


推荐阅读