How do I setup Connection Strings for a WebJob project?

假装没事ソ 提交于 2019-12-02 20:19:18

I found that providing a value for

 <Destination Path="" /> 

in your publish profile pubxml file got rid of the issue. This can usually be found in \Properties\PublishProfiles. You probably have something like:

<PublishDatabaseSettings>
  <Objects xmlns="">
    <ObjectGroup Name="Context" Order="1" Enabled="False">
      <Destination Path="" />
      <Object Type="DbCodeFirst">
        <Source Path="DBMigration" DbContext="Context, DAO" MigrationConfiguration="Context.Migrations.Configuration, DAO" Origin="Convention" />
      </Object>
    </ObjectGroup>
  </Objects>
</PublishDatabaseSettings>

Changing it to the following fixed it for me:

<PublishDatabaseSettings>
  <Objects xmlns="">
    <ObjectGroup Name="Context" Order="1" Enabled="False">
      <Destination Path="{deployment connection string}" />
      <Object Type="DbCodeFirst">
        <Source Path="DBMigration" DbContext="Context, DAO" MigrationConfiguration="Context.Migrations.Configuration, DAO" Origin="Convention" />
      </Object>
    </ObjectGroup>
  </Objects>
</PublishDatabaseSettings>

Hope that helps.

I found that deleting the obj directory within the WebJob project will clear the staging area in which the WebJob package to be published is being built. Publish was then successful.

Reason of the problem
Change the name of the connection string in the Web.Config or/and adding a new connection string to the Web.Config.

Solution

  1. Select the website project, right click on it, and click publish.


  1. Press the settings link and from the pop-up window select the 'Settings' Tab

  2. Uncheck the use this connection string at runtime from all your connection strings.

  1. Click Save button to close the the window. (No need to Restart Visual Studio)
  2. Try to publish the website again, and it should publish without problem.

NOTE
I am using VS 2017

Just for Note
After I did the previous steps, I noticed that the .pubxml file changed automatically. here is the difference which has been made (automatically without any interference from me)

So I think this is better way because it is easier for developer and also it let the visual studio to solve its problems himself, without forcing it for specific thing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!