Object context could not be created.

.net asp.net-mvc c# entity-framework

Question

I'm acquiring theUnable to create object context ASP.NET MVC encounters an issue while utilizing Entity Framework.

Background

The moment IPOST towards the controller I'm not hearing back from anybody. I made an attempt to access the controller's method directly./Data/GetAll Get the following 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 fragment that raises 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=&quot;Data Source=host;User ID=myuseracc;Password=******;
MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

What may I be overlooking?

1
4
4/4/2011 6:57:20 PM

Popular Answer

I believe I have identified the issue based on the comments.

You just need to make sure that the connection string is defined in the model's separate assembly if it is.app.config /web.config of the model's every assembly. I'm assuming that the model project is the only place you have it.

See this inquiry and this MSDN thread for other examples. Models being in distinct projects or assemblies caused both of these related problems. I'm almost certain that this is connected to your problem.

7
5/23/2017 10:29:47 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow