title: Connection string to remote DB when using EntityFramework
body: <p>I have an ASP.NET MVC application, and I'm making use of EntityFramework 5.0. I've also installed a 'CodeFirstMembershipProvider' Nuget package, which provided some code for ASP.NET membership - and I believe also made changes to my web.config. </p>
  
  <p>Basically, my problem is that my application works fine on a local SQL Server instance, but when I specify a remote DB using this connection string: </p>
  
  <blockquote>
  <pre><code>    &lt;add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=*******************, 14330;Integrated Security=False;Database=qrcodetr_database;Uid=qrcodetr_admin;Password=*********; Connect Timeout=15;Encrypt=False;Network Library=dbmssocn;Packet Size=4096" /&gt;
  </code></pre>
  </blockquote>
  
  <p>(password and hostname edited out)</p>
  
  <p>it fails to use this connection string. It continues to attempt to use the local SQL Server instance instead - so it works locally but when I try it on my web and database host it fails - since it tries to use a local SQL server instance which it can't do on my database host. The remote database host uses SQL Server 2008 R2. </p>
  
  <p>Does anyone know why this might be or what I can do to solve this? </p>
  
  <p>I'm not going to post the whole web.config, but here's a few lines that might be relevant: </p>
  
  <pre><code>&lt;add key="DatabaseInitializerForType TreasureHuntDB, QrCodeTreasureHunter" value="DataContextInitializer, QrCodeTreasureHunter"
  </code></pre>
  
  <blockquote>
  <pre><code>&lt;sessionState mode="InProc" customProvider="DefaultSessionProvider"&gt;
    &lt;providers&gt;
      &lt;add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" /&gt;
    &lt;/providers&gt;
  &lt;/sessionState&gt;
  &lt;membership defaultProvider="CodeFirstMembershipProvider"&gt;
    &lt;providers&gt;
      &lt;add name="CodeFirstMembershipProvider" type="CodeFirstMembershipProvider" connectionStringName="DefaultConnection" /&gt;
    &lt;/providers&gt;
  &lt;/membership&gt;
  &lt;roleManager enabled="true" defaultProvider="CodeFirstRoleProvider"&gt;
    &lt;providers&gt;
      &lt;clear /&gt;
      &lt;add name="CodeFirstRoleProvider" type="CodeFirstRoleProvider" connectionStringName="DefaultConnection" /&gt;
    &lt;/providers&gt;
  &lt;/roleManager&gt;
  </code></pre>
  </blockquote>
  
  <pre><code>      &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;
    &lt;/entityFramework&gt;
  </code></pre>
  
  <p>I'm able to successfully connect to the remote DB via SQL Server 2008, by the way, so the issue definitely seems to be a configuration issue on my end. </p>
  
  <p>By the way, I am using a DataContextInitializer which is set to 'CreateDatabaseIfNotExists'. I have set it to this because on the hosted database, I don't have permissions to CREATE or DROP the database, so what I've done is I've created a backup of one of the ones created locally (in SQL Server Express) and used the restore feature to restore the file to my hosted database. So I have a database in place, it just won't work with my application. </p>