0

I have these files:

Web.config

 <connectionStrings>
 </connectionStrings>

Web.Debug.config

  <connectionStrings>
    <add name="Elite.DAL.MainContext"
     connectionString="Data Source=FISH\SQLEXPRESS;Initial Catalog=Elite;Integrated Security=True"
     providerName="System.Data.SqlClient" />
  </connectionStrings>

Web.Releas.config

  <connectionStrings>
    <add name="Elite.DAL.MainContext"
         connectionString="Data Source=1LEINTRA\SFSQL;Initial Catalog=Elite;Integrated Security=True"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

Am I doing something wrong?

When I publish using Web-Deploy I get this:

  <connectionStrings>
    <add name="Elite.DAL.MainContext" connectionString="Elite.DAL.MainContext_ConnectionString" providerName="System.Data.SqlClient" />
    <add name="Elite.DAL.MainContext_DatabasePublish" connectionString="Elite.DAL.MainContext_DatabasePublish.ConnetionString" providerName="System.Data.SqlClient" />
  </connectionStrings>

Format of the initialization string does not conform to specification starting at index 0.

Additionally, when I publish I select run first code migrations but tables are not created which is part of initial migration.

<contexts>
  <context type="Elite.DAL.MainContext, Elite">
    <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[Elite.DAL.MainContext, Elite], [Elite.Migrations.Configuration, Elite]], EntityFramework, PublicKeyToken=b77a5c561934e089">
      <parameters>
        <parameter value="Elite.DAL.MainContext_DatabasePublish" />
      </parameters>
    </databaseInitializer>
  </context>
</contexts>
d0001
  • 2,162
  • 3
  • 20
  • 46

1 Answers1

0

You should put the Debug connection string in your regular web.config. Then you can use XML-Document-Transform options like to configure your release build.

You can then tell the transformation process that you want to change the connection string in the regular web.config like this:

  <add name="lite.DAL.MainContext" 
      connectionString="Data Source=1LEINTRA\SFSQL;Initial Catalog=Elite;Integrated Security=True" 
      xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>

You can find the documentation for the Web.config transformation syntax here.

If you do want to keep an empty web.config you can use the following syntax:

<connectionStrings xdt:Transform="Replace" >
    <add name="Elite.DAL.MainContext"
     connectionString="Data Source=FISH\SQLEXPRESS;Initial Catalog=Elite;Integrated Security=True"
     providerName="System.Data.SqlClient"/>
  </connectionStrings>

By putting this in your web.debug.config and web.release.config you configure that the whole (empty) connectionStrings element from your web.config should be replaced.

Wouter de Kort
  • 39,090
  • 12
  • 84
  • 103
  • I tried that with no success. I unchecked the "run first code migrations" from web-deploy and it only created one connection string. And what is weird now is that with the option checked off now system is trying to create the tables from the initial migration. – d0001 Jul 16 '14 at 19:06
  • I don't see what migrations have to do with the transformation on your web.config not working. Have you tried previewing your transformation with a tool like SlowCheetah? – Wouter de Kort Jul 16 '14 at 19:07