C# 警告:源文档中没有与'/配置/连接字符串/添加[@name=';MyDB';]';
我有一个asp.net项目需要发布到Azure 这是我的网络配置文件C# 警告:源文档中没有与'/配置/连接字符串/添加[@name=';MyDB';]';,c#,.net,asp.net-mvc,azure,C#,.net,Asp.net Mvc,Azure,我有一个asp.net项目需要发布到Azure 这是我的网络配置文件 <?xml version="1.0"?> <!-- For more information on using Web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=301874 --> <configuration xmlns:xdt="http://schemas.microsoft.com/XML
<?xml version="1.0"?>
<!-- For more information on using Web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=301874 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyDB"
connectionString="Server=tcp:vchasnotestserver.database.windows.net,1433;Initial Catalog=vchasnotestdb;Persist Security Info=False;User ID=***;Password=********;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
当我部署到azure时,我会在输出中收到此警告
2> C:\Users\nemes\Source\Repos\vchasnocrm new\vchasnocrm\Web.Release.config(7,8):警告:源文档中没有与“/configuration/connectionStrings/add[@name='MyDB']”匹配的元素
如何修复此问题?根据您在
Web.Release.config
下的Web.config转换,转换代码有效。对于您提供的警告消息:
警告:源文档中没有与“/configuration/connectionStrings/add[@name='MyDB']匹配的元素
根据我的测试,这意味着在Web.config
文件下不存在名为MyDB
的connectionString
。因此,您可以忽略此警告消息。要在部署到azure之前覆盖connectionString,您需要确保有一个名为MyDB
的connectionString,或者需要调整Web.Release.config
文件下的connectionString名称
此外,如果您使用Azure Web应用程序托管您的Web应用程序,您可以利用Azure应用程序服务中的应用程序设置在运行时覆盖您的现有设置。根据您的要求,您可以登录Azure Portal并选择web应用程序,单击“设置>应用程序设置”,然后添加与
web.config
文件下定义的名称相同的连接字符串。您可以遵循的详细信息。根据您在Web.Release.config
下的Web.config转换,转换代码是有效的。对于您提供的警告消息:
警告:源文档中没有与“/configuration/connectionStrings/add[@name='MyDB']匹配的元素
根据我的测试,这意味着在Web.config
文件下不存在名为MyDB
的connectionString
。因此,您可以忽略此警告消息。要在部署到azure之前覆盖connectionString,您需要确保有一个名为MyDB
的connectionString,或者需要调整Web.Release.config
文件下的connectionString名称
此外,如果您使用Azure Web应用程序托管您的Web应用程序,您可以利用Azure应用程序服务中的应用程序设置在运行时覆盖您的现有设置。根据您的要求,您可以登录Azure Portal并选择web应用程序,单击“设置>应用程序设置”,然后添加与
web.config
文件下定义的名称相同的连接字符串。您可以遵循的详细信息。这可能会有所帮助:但对于auth,我有错误db@RuiJarimbait阅读他的答案,这是一个类似的问题。请尝试将xdt:Transform=“SetAttributes”xdt:Locator=“Match(name)”
替换为xdt:Transform=“SetAttributes(name)”
这可能会有所帮助:但这是用于身份验证的,我犯了一个错误db@RuiJarimbait请阅读他的答案。尝试将xdt:Transform=“SetAttributes”xdt:Locator=“Match(name)”替换为xdt:Transform=“SetAttributes(name)”
。是的,我的数据库工作得很好。但这条信息看起来令人困惑,谢谢。是的,我的数据库工作得很好。但这条信息看起来令人困惑