One-click publish in vs 2012: how to remove _ConnectionStringsToInsert?
Asked Answered
H

3

12

I usually put my connection string to a separate file, adding something like this in web.config:

<connectionStrings configSource="WebConnection.config" />

I've just installed VS 2012 and it automatically picked up my existing publish settings. However, when I do a webpublish it now adds two connections strings by itself, so my web.config on the deployment target now looks like that:

  <connectionStrings configSource="WebConnection.config">
    <add name="EF.Model.DbContext" connectionString="EF.Model.DbContext_ConnectionString" providerName="System.Data.SqlClient" />
    <add name="Migrations.Db.MigrationDb" connectionString="Migrations.Db.MigrationDb_ConnectionString" providerName="System.Data.SqlClient" />
  </connectionStrings>

certainly, that produces an error (node contents must be empty when using configSource). I noticed, that in newly generated .pubxml files (where publish settings are now stored) there are following lines:

  <ItemGroup>
    <_ConnectionStringsToInsert Include="EF.Model.DbContext" />
    <_ConnectionStringsToInsert Include="Migrations.Db.MigrationDb" />
  </ItemGroup>

How can I remove them? :) If I delete them from file, Web-publish dialog adds them anytime I edit the publish settings.

Hapten answered 6/6, 2012 at 8:2 Comment(2)
Sorry you are running into this, we have filed a bug for this and will try and take care of this.Proposition
@SayedIbrahimHashimi Do you know if this bug was ever resolved? I'm running into this issue.Wormhole
H
6

I suddenly resolved that by going to project properties, "Package/Publish Web" and checking the mark "Include all databases configured in P/P SQL tab" (and I don't have any DB configured there :)).

After doing this and deleting the mentioned lines from .pubxml everything went fine.

Seems like a hack, but it was a way to go for me :)

@Sayed, thanks for confirming it's a bug, hope it'll be resolved!

Hapten answered 8/6, 2012 at 9:22 Comment(1)
This fix doesn't seem to make those lines stay away. They still return whenever you go to the connection strings configuration page in the Publish dialog.Nubble
A
4

I came up with a (possibly) less hacky solution for bypassing the bug in publish that forces discovered Entity Framework code first db contexts to have a connection string. This is still an issue that I'm having in VS 2013.

In your web.config, add a dummy version of the connection string:

<add name="DbContextName" connectionString="This is a dummy connection string to bi-pass publish bug." providerName="System.Data.SqlClient" />

Now, setup a transform for the configuration you want to create a publish package for. Read more about it here.

In your web.config.{configuration} file, use the following transform to remove the connection string:

<connectionStrings>
  <add name="DbContextName" xdt:Transform="Remove" xdt:Locator="Match(name)"/>
</connectionStrings>

This transform runs AFTER the publish transform in your pubxml runs, so it clears out the unwanted connection string.

Acquirement answered 17/3, 2014 at 21:37 Comment(2)
If you don't have migrations enabled as per the answer from tdykstra, this seems to be the only solution. The Web Deploy process won't try to add connection strings if it sees them already in the web.config file, and the build transform happily removes them from the web.config file during the build process.Intensifier
This solution also worked for me, the only change I've made was on the Web.Release.config, using this <connectionStrings xdt:Transform="Remove" /> removed all of the connection strings on a one-liner.Stringency
G
1

On the Settings tab of the publish profile, clear the Use this connection string at runtime check box and the Apply Code First migrations check box. Make sure that migrations is enabled, or the Use this connection string box won't stay cleared, and even then you may have to clear it again each time you open the profile.

Gynous answered 6/6, 2012 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.