Entity Framework – Connection Strings

Technorati Tags:

See:

http://msdn.microsoft.com/en-us/library/vstudio/cc716756(v=vs.100).aspx

Entity Framework connection string for Entity Model

If in a different project in the same solution and a folder in that project then.


res://Project.ProjectName/Folder.ModelName.csdl|
res://Project.ProjectName/Folder.ModelName.ssdl|
res://Project.ProjectName/Folder.ModelName.msl;

If you struggle then the following will work, but may not be as efficient because the application has to search through available references. This is all that is needed though.


res://*/

 

  <connectionStrings>
    <add name="MovieModel"
         connectionString="metadata=res://OneWay.EntityModel/Models.MovieModel.csdl|
                                    res://OneWay.EntityModel/Models.MovieModel.ssdl|
                                    res://OneWay.EntityModel/Models.MovieModel.msl;
                                    provider=System.Data.SqlClient;
                                    provider connection string=
                                      "data source=(local);
                                      initial catalog=DBName;
                                      integrated security=True;
                                      multipleactiveresultsets=True;
                                      App=EntityFramework;""
         providerName="System.Data.EntityClient" />

    <add name="OneWayEntitiesCF"
         connectionString="Data Source=(local);Initial Catalog=OneWay;Integrated Security=True"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

Error 1: System.IO.FileNotFoundException: Unable to resolve assembly ‘OneWay.EntityMode’.

Solution is to correct res://[this bit]/..

Error 2: System.Data.Entity.Core.MetadataException: Unable to load the specified metadata resource.

Solution is to correct res://../[ThisBit]

Possibly you require FolderName.ModelName.

 

Other notes

If do not have Initial Catalog then will attach it to program and detach itself from SQL. Agh ! May also need User Instance = False for this.

Connection string in App.config.

Name and Model name need to match.

In edmx change Entity Set Names to have an ‘s’ on the end for each entity

Good luck !

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: