“DefaultConnection-Web.config连接字符串”参数不能为null或为空。 VS2013

问题描述 投票:39回答:4

当我使用Visual Studio 2013 / update 4使用“发布为Azure WebJob”部署项目时,我在标题中收到错误。

visual-studio-2013 azure-webjobs
4个回答
39
投票

通过从.pubxml文件中删除以下标记来解决此问题。删除标记后必须退出/重新启动VS(或VS将其重新添加)。

<ItemGroup>
  <MSDeployParameterValue Include="$(DeployParameterPrefix)DefaultConnection-Web.config Connection String" />
</ItemGroup>

14
投票

问题的原因 在web.config中更改和/或添加连接字符串的名称。

  1. 选择网站项目,右键单击它,然后单击“发布”。 enter image description here

  1. 按设置链接,然后从弹出窗口中选择“设置”选项卡
  2. 从所有连接字符串中取消选中use this connection string at runtime

enter image description here

  1. 单击Save按钮关闭窗口。 (无需重新启动Visual Studio)
  2. 尝试再次发布网站,它应该没有问题发布。

注意 我正在使用VS 2017(根据评论,这项工作也在Visual Studio 2013中)

只是为了注意 完成前面的步骤后,我注意到.pubxml文件自动更改。这是差异(自动没有任何干扰)

所以我认为这是一种更好的方式,因为它对开发人员来说更容易,也让视觉工作室自己解决问题,而不会强迫它进入特定的事情。

enter image description here


11
投票

使用以下内容在Project根目录中创建Parameters.xml文件:

<?xml version="1.0" encoding="utf-8" ?>
<parameters>
  <parameter name="DefaultConnection-Web.config Connection String"
      description="DefaultConnection"
      defaultValue="Server=tcp:x.database.windows.net,1433;Database=x_db;User ID=x@y;Password=z;Trusted_Connection=False;etc." tags="" />
</parameters>

所有其他缺少的配置元素也可以添加到这里。


4
投票

我有Visual Studio 2015 Update 3,我面临同样的问题。我发现对我有用的解决方案如下:

1)打开属性 - >发布配置文件下的* .pubxml文件。

2)在PublishDatabaseSettings部分下查找Path属性:

<PublishDatabaseSettings>
      <Objects xmlns="">
        <ObjectGroup Name="eRecall.ETL.Models.erecallContext" Order="1" Enabled="False">
          <Destination Path="" />
          <Object Type="DbCodeFirst">
            <Source Path="DBContext" DbContext="eRecall.ETL.Models.erecallContext, eRecall.ETL" />
          </Object>
        </ObjectGroup>
      </Objects>
    </PublishDatabaseSettings> 

3)将Path属性值设置为以下值:

<PublishDatabaseSettings>
      <Objects xmlns="">
        <ObjectGroup Name="eRecall.ETL.Models.erecallContext" Order="1" Enabled="False">
          <Destination Path="{deployment connection string}" />
          <Object Type="DbCodeFirst">
            <Source Path="DBContext" DbContext="eRecall.ETL.Models.erecallContext, eRecall.ETL" />
          </Object>
        </ObjectGroup>
      </Objects>
    </PublishDatabaseSettings>

4)删除Azure作业收集计划程序中的现有Webjob部署。

5)重新部署webjob,从调度程序重新运行webjob,它开始工作没有问题!

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.