I get a Unable to create object context error when using the Entity framework in ASP.NET MVC.
Background
Every time I POST to the controller, I do not get a response. I tried to go directly to the controller method /Data/GetAll and get this error:
Error
The specified named connection is either not found in the configuration, is not intended for use with EntityClient, or is invalid. 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 occurred in the code.
Exception Details: System.ArgumentException: specified named connection was either not found in the configuration and was not intended to be used with EntityClient, or is invalid.
A snippet of code that throws an 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 can I lose?
source share