I'm getting the Unable to create object context
error when using Entity framework in ASP.NET MVC.
Background
Every time I POST
to the controller I'm not getting a response back. I tried going directly to the method of the controller /Data/GetAll
, and receive this error:
Error
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:
System.ArgumentException:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
Code Snippet that throws exception:
public class TrackItContextCreator {
public ObjectContext Create() {
ObjectContext context = new ObjectContext("name=TrackItDBEntities");
context.DefaultContainerName = "TrackItDBEntities";
return context;
}
}
Web.config
<add name="TrackItDBEntities" connectionString="metadata=res://*
/EntityFramework.TrackItDBModel.csdl|res://*/EntityFramework.TrackItDBModel.ssdl|res:
//*/EntityFramework.TrackItDBModel.msl;provider=System.Data.SqlClient;provider
connection string="Data Source=host;User ID=myuseracc;Password=******;
MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
What could I be missing?