Search code examples
asp.net-mvcentity-frameworkexceptionconnection-string

Data Entities Connection String Problem


I must have changed something somewhere, but damned if I can figure out what it is.

I have a DAL that handles all my data access (as is a DAL's wont) to my SQL Server DB. This includes the Entity Model, the repository classes and the connection string in the App.Config file.

Somewhere along the piece, I must have changed something and am now getting the following exception every time I try to view a page on my MVC application:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

This is any page that inherits <IEnumerable<DataAccess.Layer.Class>>. What am I missing?

Connection String:

<add name="JobTrackEntities" 
     connectionString="metadata=res://*/JobTrackDataModel.csdl|res://*/JobTrackDataModel.ssdl|res://*/JobTrackDataModel.msl;provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;C:\Users\Phil\Documents\Visual Studio 2010\Projects\JobTrack\trunk\JobTrack\App_Data\JobTrack.MDF&quot;;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True'" providerName="System.Data.EntityClient" />

Designer.cs snippet:

public JobTrackEntities() : 
        base("name=JobTrackEntities", "JobTrackEntities")
{
    this.OnContextCreated();
}
/// <summary>
/// Initialize a new JobTrackEntities object.
/// </summary>
public JobTrackEntities(string connectionString) : 
        base(connectionString, "JobTrackEntities")
{
    this.OnContextCreated();
}
/// <summary>
/// Initialize a new JobTrackEntities object.
/// </summary>
public JobTrackEntities(global::System.Data.EntityClient.EntityConnection connection) : 
        base(connection, "JobTrackEntities")
{
    this.OnContextCreated();
}

Solution

  • If you are referring your ADO.NET entity project in another project then take a look at

    http://blogs.msdn.com/bindeshv/archive/2009/09/04/referring-ado-net-entity-project-in-a-different-project.aspx