views:

460

answers:

3

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();
}
A: 

At the risk of getting a down vote I notice, whenever i use a S2L dbml class that I run into the same problem when i make a change to the dbml file via the interface and not in code.

it resets my connection string and i need to change it back to read from web.config.

don't know if this is your issue @Phil.

if not, could you provide more information?

griegs
Well, I looked at that and the designer.cs file still references the correct connection string and doesn't seem to have any other connection details cached anywhere. I'll add the source in my OP.
Phil.Wheeler
+2  A: 

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

Rasik Jain
That's automatically inserted by the ORM designer in Visual Studio. My understanding is that it will convert those HTML codes to their string equivalents when the App.Config file's XML is parsed. However, if anyone else can confirm that this could be an issue, I'd like to know.
Phil.Wheeler
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
Rasik Jain
@Rasik. Well done, that man! I knew it would be something simple. You should enter this as the actual answer so I can accept it as the solution and upvote it.
Phil.Wheeler
Phil, As per your comment, I have modified the answer.
Rasik Jain
A: 

The only other thing I can see that may cause a problem is the use of the hard coded path. Have you tried inserting a \?

C:\\Users\\Phil\\Documents\\Visual Studio 2010\\Projects\\JobTrack\\trunk\\JobTrack\\App_Data\\JobTrack.MDF

Also I trust you've checked and double checked the path is correct? :)

Have you tried getting the server path and then adding app_data\jobtrack.mdf to it?

Have you tried getting rid of the path entirley? I ask because, and I forget under what circumstances this is correct, .Net will infer the path and app_data folder when attaching to a database. again, you need to research this.

Also sometimes running the ASP.NET Configuration utility can fix the project, break the project or identify where the problem is.

griegs