title: Connection to the database failed. Check that connection string is correct and DbContext constructor
body: <p>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.</p>
  
  <p>I swear I tried everything!  Going through this tutorial and struggling to get connection to the database.</p>
  
  <p>My table in SQL Server 2012 is called, "tblEmployee" and the database is called "Sample"</p>
  
  <p>This is the Employee.cs class</p>
  
  <pre><code>[Table("tblEmployee")]
  public class Employee
  {
      public int EmployeeID { get; set; }
      public string Name { get; set; }
      public string City { get; set; }
      public string Gender { get; set; }
  }
  </code></pre>
  
  <p>This is the employee context model class</p>
  
  <pre><code>public class EmployeeContext : DbContext
  {
      public DbSet&lt;Employee&gt; Employees { get; set; }
  }
  </code></pre>
  
  <p>This is the EmployeeControler</p>
  
  <pre><code>public class EmployeeController : Controller
  {
      public ActionResult Details()
      {
          EmployeeContext employeeContext = new EmployeeContext();
          Employee employee = employeeContext.Employees.Single(emp =&gt; emp.EmployeeID == 2);
          return View(employee);
      }
  }
  </code></pre>
  
  <p>This is the web.config file</p>
  
  <pre><code>&lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
      &lt;parameters&gt;
          &lt;parameter value="v11.0" /&gt;
      &lt;/parameters&gt;
     &lt;/defaultConnectionFactory&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;
  </code></pre>
  
  <p>And this is the connection string</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="EmployeeContext" connectionString="Data Source=ADMIN-PC;Initial Catalog=Sample;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>Nothing special on the actual View</p>
  
  <pre><code>@{
  ViewBag.Title = "Employee Details";
  }
  
  &lt;h2&gt;Employee Details&lt;/h2&gt;
  
  &lt;table style="font-family:Arial"&gt;
      &lt;tr&gt;
          &lt;td&gt;EmployeeID:&lt;/td&gt;
          &lt;td&gt;@Model.EmployeeID&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Name:&lt;/td&gt;
          &lt;td&gt;@Model.Name&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Gender:&lt;/td&gt;
          &lt;td&gt;@Model.Gender&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;City:&lt;/td&gt;
          &lt;td&gt;@Model.City&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>This is the stack trace</p>
  
  <pre><code>at System.Data.Entity.ModelConfiguration.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
  at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
  at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
  at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
  at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
  at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
  at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
  at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
  at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
  at System.Linq.Queryable.Single[TSource](IQueryable`1 source, Expression`1 predicate)
  at MVCDemo.Controllers.EmployeeController.Details() in c:\Users\Admin\Documents\Visual Studio 2013\Projects\MVCDemo\MVCDemo\Controllers\EmployeeController.cs:line 19
  at lambda_method(Closure , ControllerBase , Object[] )
  at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
  at System.Web.Mvc.Async.AsyncControllerActionInvoker.&lt;&gt;c__DisplayClass37.&lt;&gt;c__DisplayClass39.&lt;BeginInvokeActionMethodWithFilters&gt;b__33()
  at System.Web.Mvc.Async.AsyncControllerActionInvoker.&lt;&gt;c__DisplayClass4f&lt;InvokeActionMethodFilterAsynchronously&gt;b__49()
  </code></pre>