title: Entity framework database connection error
body: <p>I am using the Entity framework (code first) first time. I have created a context class with the following code.</p>
  
  <pre><code>public class ContactContext : DbContext
  {
      public ContactContext()
          : base("DBConnectionString")
      {
          Database.SetInitializer&lt;ContactContext&gt;(new DropCreateDatabaseIfModelChanges&lt;ContactContext&gt;());
      }
  
      public DbSet&lt;Contact&gt; Contacts { get; set; }
  
  }
  </code></pre>
  
  <p>Web.config file:
  </p>
  
  <pre><code>&lt;add name="ContactMgrDBContext" connectionString="Data Source=(Local);Initial Catalog=ContactsDB;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>Controller class:</p>
  
  <pre><code>public class ContactController : Controller
  {
  
      ContactContext db = new ContactContext();
  </code></pre>
  
  <p>//
          // GET: /Contact/</p>
  
  <pre><code>    public JsonResult ContactList(int? selectedContact)
      {
  
          IQueryable&lt;Contact&gt; contacts = db.Contacts;
  
          //contacts.ToList()
  
          var contactsJson = JsonConvert.SerializeObject(contacts.ToList());
  
          return Json(contactsJson, JsonRequestBehavior.AllowGet);
  
  }
  </code></pre>
  
  <p>When I run the application in debug mode, I get the following exception at this statement.</p>
  
  <pre><code>var contactsJson = JsonConvert.SerializeObject(contacts.ToList());
  </code></pre>
  
  <p><strong>An exception of type 'System.Data.ProviderIncompatibleException' occurred in EntityFramework.dll but was not handled in user code
  Additional information: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.</strong></p>
  
  <p>Contact class code:</p>
  
  <pre><code>public class Contact
   {
      [Key]
      public int ContactId { get; set; }
      [Required, MaxLength(100)]
      public string FirstName { get; set; }
      [Required, MaxLength(100)]
      public string LastName { get; set; }
      public string EMail { get; set; }
      public string Phone { get; set; }
      public string BusinessName { get; set; }
  
   }
  </code></pre>