title: Determine correct connectionString for web publishing for ASP.NET-MVC application
body: <p>During development of ASP.NET-MVC application on local machine I used this <code>connectionString</code>with no problems whatsoever:</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\AppDb.mdf;Initial Catalog=AppDb;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>In hosting service database control panel I can get connection string to my MSSQL(I selected SQL Server 2012 database, but I can choose 2014 if it helps). They say connection string is:</p>
  
  <pre><code>"Data Source=SQL5013.myASP.NET;Initial Catalog=DB_9B42A0_baza;User Id=DB_9B42A0_baza_admin;Password=YOUR_DB_PASSWORD;"
  </code></pre>
  
  <p>Info about my MSSQL database:</p>
  
  <pre><code>Server name :   SQL5013
  Server version :    Microsoft SQL Server 2012 - 11.0.5058.0 (X64) 
  May 14 2014 18:34:29 
  Standard Edition (64-bit) on Windows NT 6.3 (Build 9600: )
  Database name:DB_9B42A0_baza    
  Server URL:SQL5013.myASP.NET    
  Login name:DB_9B42A0_baza_admin
  </code></pre>
  
  <p>My application is ASP.NET-MVC5.1 with Entity Framework 6.</p>
  
  <p><strong>Here it is what I have tried:</strong></p>
  
  <h2><b>Attempt 1</b></h2>
  
  <p>Added this connection definition between <code>&lt;connectionStrings&gt; &lt;/connectionStrings&gt;</code></p>
  
  <pre><code> &lt;add name="DefaultConnection" connectionString="Data Source=SQL5013.myASP.NET;Initial Catalog=DB_9B42A0_baza;User Id=DB_9B42A0_baza_admin;Password=12345678;" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>Result when accessing my website: </p>
  
  <pre><code>Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
  </code></pre>
  
  <h2><b>Attempt 2</b></h2>
  
  <pre><code>&lt;add name="DefaultConnection" connectionString="Provider=sqloledb;Data Source=SQL5013,1433;Initial Catalog=DB_9B42A0_baza;User Id=DB_9B42A0_baza_admin;Password=12345678;" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>Result when accessing my website:</p>
  
  <pre><code>Exception Details: System.ArgumentException: Keyword not supported: 'provider'.
  </code></pre>
  
  <h2><b>Attempt 3</b></h2>
  
  <pre><code>&lt;add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\AppDb.mdf;Initial Catalog=AppDb;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>Plus in WebApplication2(this is the name of my ASP.NET-MVC application) properties:</p>
  
  <p><img src="https://i.stack.imgur.com/PvM8V.png" alt="enter image description here"></p>
  
  <p>Result when accessing my website:</p>
  
  <pre><code>Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
  </code></pre>
  
  <h2><b>Attempt 4 (based on first example from http://www.connectionstrings.com/sqlconnection/ )</b></h2>
  
  <pre><code>&lt;add name="DefaultConnection" connectionString="Server=SQL5013.myASP.NET;Database=DB_9B42A0_baza;User Id=DB_9B42A0_baza_admin;Password=12345678;" providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>Result when accessing my website:</p>
  
  <pre><code>Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
  </code></pre>
  
  <h2><b>Summary:</b></h2> 
  
  <p>I tried many more things to make it work during last 3 days which I don't remember. I read lot of MSDN articles and no luck. If I can supply any more information about the database or application please tell I will update post shortly.</p>
  
  <h2><b>Question:</b></h2>
  
  <p>What should I write in  <code>&lt;connectionStrings&gt; &lt;/connectionStrings&gt;</code> seciton to make the database connection work after I publish it?</p>
  
  <hr>
  
  <h2><b>Additional info:</b></h2>
  
  <p>My full <code>Web.config</code> file is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;   
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
      &lt;add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\AppDb.mdf;Initial Catalog=AppDb;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;system.web&gt;
      &lt;customErrors mode="Off"/&gt;
    &lt;/system.web&gt;
    &lt;appSettings&gt;
      &lt;add key="webpages:Version" value="3.0.0.0" /&gt;
      &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;add key="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;authentication mode="None" /&gt;
      &lt;compilation debug="true" targetFramework="4.5.1" /&gt;
      &lt;httpRuntime targetFramework="4.5.1" /&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;modules&gt;
        &lt;remove name="FormsAuthenticationModule" /&gt;
      &lt;/modules&gt;
    &lt;/system.webServer&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <h2><b>Update -> code resposible for database</b></h2>
  
  <p><code>Application_Start</code> in <code>Global.asax</code></p>
  
  <pre><code>namespace WebApplication2 {
      public class MvcApplication : System.Web.HttpApplication {
          protected void Application_Start() {
              System.Diagnostics.Debug.WriteLine("Application_Start");
              Database.SetInitializer(new MigrateDatabaseToLatestVersion&lt;ApplicationDbContext, Configuration&gt;());
              new ApplicationDbContext().Database.Initialize(true);
              AreaRegistration.RegisterAllAreas();
              FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
              RouteConfig.RegisterRoutes(RouteTable.Routes);
              BundleConfig.RegisterBundles(BundleTable.Bundles);
          }
      }
  }
  </code></pre>
  
  <p>and the <code>Configuration/Migrations.cs</code> file:</p>
  
  <pre><code>namespace WebApplication2.Migrations {
      using Microsoft.AspNet.Identity;
      using Microsoft.AspNet.Identity.EntityFramework;
      using System;
      using System.Collections.Generic;
      using System.Data.Entity.Migrations;
      using System.Data.Entity.Validation;
      using System.Linq;
      using WebApplication2.Models;
  
      internal sealed class Configuration : DbMigrationsConfiguration&lt;WebApplication2.Models.ApplicationDbContext&gt; {
          public Configuration() {
              AutomaticMigrationsEnabled = true;
              AutomaticMigrationDataLossAllowed = true;
              ContextKey = "WebApplication2.Models.ApplicationDbContext";
          }
  
          protected override void Seed(WebApplication2.Models.ApplicationDbContext context) {
              System.Diagnostics.Debug.WriteLine("SEED STARTED");
  
          }
      }
  }
  </code></pre>
  
  <p>and <code>Models/IdentityModels.cs</code> where is my <code>DbContext</code> defined:</p>
  
  <pre><code>using System.Security.Claims;
  using System.Threading.Tasks;
  using Microsoft.AspNet.Identity;
  using Microsoft.AspNet.Identity.EntityFramework;
  using System.Data.Entity;
  using System.Data.Entity.ModelConfiguration.Conventions;
  using System;
  using System.Collections.Generic;
  
  namespace WebApplication2.Models {
      // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
      public class ApplicationUser : IdentityUser {
  
          USER PROPERTIES HERE
  
          public async Task&lt;ClaimsIdentity&gt; GenerateUserIdentityAsync(UserManager&lt;ApplicationUser&gt; manager) {
              // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
              var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
              // Add custom user claims here
              return userIdentity;
          }
      }
  
      public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt; {
  
  
          public ApplicationDbContext()
              : base("DefaultConnection", throwIfV1Schema: false) {
              System.Diagnostics.Debug.WriteLine("CONSTRUCTOR");
              Configuration.LazyLoadingEnabled = true;
              Configuration.ProxyCreationEnabled = true;
          }
  
         DBSETS HERE
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder) {
              base.OnModelCreating(modelBuilder);
              modelBuilder.Entity&lt;Person&gt;().HasMany(p =&gt; p.Answers).WithMany(a =&gt; a.Persons);
              modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
          }
  
          public static ApplicationDbContext Create() {
  
              return new ApplicationDbContext();
  
          }
  
  
      }
  }
  </code></pre>
  
  <h2><b>Foot note</b></h2>
  
  <p>I am not eligible to start bounty before 2 days from asking a question but if this helps I offer 500 reputation points for working connection string (I will award it when the bounty will be possible). It is too hard to me and I tried countless things for 3 days.</p>