title: Entity Framework: Connect to an external database
body: <p>I have created application under MS VS 2012 express. I am using Entity Framework to access local database SQL Server Compact 4.0. Everything works just fine:</p>
  
  <p>Web.config</p>
  
  <pre><code>  &lt;connectionStrings&gt;
     &lt;add name="KMDBContext" connectionString="Data Source=|DataDirectory|\kmdbs.sdf" providerName="System.Data.SqlServerCe.4.0"/&gt;
    &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>LessonsL.cs</p>
  
  <pre><code>public class KMDBContext : DbContext
  {
      public DbSet&lt;LessonsL&gt; LessonsLs { get; set; }
  }
  </code></pre>
  
  <p>LessonsLController.cs</p>
  
  <pre><code>private KMDBContext db = new KMDBContext();
  </code></pre>
  
  <p>But I am not able to connect to external SQL Server database. Test Connection returns positive results. I can work with the external database using MS Server Management Studio. But can not retrieve or store data. I can see the external database in Database Explorer but MS VS 2012 still connects to some local file (pdb or something).</p>
  
  <p>Web.config</p>
  
  <pre><code>  &lt;connectionStrings&gt;
      &lt;add name="LessonLs" connectionString="server=ustsql;database=LessonLs;Integrated Security=true" providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>kmd.cs</p>
  
  <pre><code>public class KMDContext : DbContext
  {
      public DbSet&lt;kmd&gt; LessonsLs { get; set; }
  }
  </code></pre>
  
  <p>KMDController.cs</p>
  
  <pre><code>private KMDContext db = new KMDContext();
  </code></pre>
  
  <p>Could anyone say what I am missing? thx</p>