title: c# Entity Framework: An error occurred accessing the database
body: <p>I have an existing application which uses mysql as database. and it's working correctly.</p>
  
  <p>But now. I need to create a version of this. In-house and for home based. </p>
  
  <p>My problem is when i update a feature or add a feature in the in-house program i also need to update the home based, the home based uses sqlite database.</p>
  
  <p>Stored procedure doesn't work in sqlite. So idecided to use entity framework. So i can easily change database. I already create a model for one of my tables</p>
  
  <p>This contains the given names for auto suggestion of my application.</p>
  
  <p>And here is my class</p>
  
  <pre><code>class Given
      {
          public int id { get; set; }
          public string name { get; set; }
          public string @operator { get; set; }
          public DateTime data_time { get; set; }
      }
  </code></pre>
  
  <p>And i used it like this</p>
  
  <pre><code>class MyDb : DbContext
      {
          public MyDb() : base("name=sample")
          {
  
          }
          public DbSet&lt;Given&gt; tble_given { get; set; }
      }
  </code></pre>
  
  <p>i named it <strong>tble_given</strong> because it's the name of my <strong>table</strong> in the database</p>
  
  <p>And this is my connection string in the App.config file</p>
  
  <pre><code>&lt;connectionStrings&gt;
  
      &lt;add name="sample" providerName="MySql.Data.MySqlClient" connectionString="server=127.0.0.1; uid=root; pwd=; database=db_sample;default command timeout=20;" /&gt;
    &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>And this is my code for accessing the data in the database</p>
  
  <pre><code>                using (var db = new MyDb())
                  {
                      db.Database.Connection.Open();
                      Debug.WriteLine(db.Database.Connection.State);
                      foreach (var item in db.tble_given.ToList())
                      {
  
                      }
                  }
  </code></pre>
  
  <p>I added the connection open and the connection state in order to check if the connection is valid.</p>
  
  <p>but when i query it. </p>
  
  <p>added the code <code>db.tble_given.ToList()</code></p>
  
  <p>Exception thrown: 'System.Data.Entity.Core.ProviderIncompatibleException' in Guatemala Coding.exe
  An exception of type 'System.Data.Entity.Core.ProviderIncompatibleException' occurred in Guatemala Coding.exe but was not handled in user code
  An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See <a href="http://go.microsoft.com/fwlink/?LinkId=386386" rel="nofollow noreferrer">http://go.microsoft.com/fwlink/?LinkId=386386</a> for information on DbContext and connections. See the inner exception for details of the failure.</p>
  
  <p>I tried solving it myself but i can't make this code work.</p>
  
  <p>Why do i have this error if the connection state is open?</p>
  
  <p>Thank you</p>