Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Connection String Trouble

I am making a little library(DLL) to manage users and their roles/privileges. The plan is to be able to add this dll to an MVC project and be able to manipulate users/roles/etc. All the data resides in a SQL db.

I am using entity framework for data access.

So when I initialize a new RoleManager(this is the name of the main class in the lib I'm making) I supply it with a connectionString like so:

RoleManager roleManager = new RoleManager(string connectionString);

Then inside the constructor I do this:

db = new RoleManagerEntities(connectionString); //This is the EntityFramework

And I am trying to supply this connection string (among many others)

"metadata=res://*/RoleManager.csdl|res://*/RoleManager.ssdl|res://*/RoleManager.msl;provider=System.Data.SqlClient;provider connection string='Data Source=localhost;Initial Catalog=Login;Integrated Security=True;Connection Timeout=60; multipleactiveresultsets=true'"

And I get the following error:

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

This question is a result of having trying to instantiate the EF from my new project without supplying a connection string and without having anything inside my app config for it to default to. Too bad I can't delete it now.

like image 962
Jason Avatar asked Oct 18 '10 19:10

Jason


People also ask

How does Entity Framework get the connection string?

The Entity Data Model tools generate a connection string that is stored in the application's configuration file. ObjectContext retrieves this connection information automatically when creating object queries. The EntityConnection used by an ObjectContext instance can be accessed from the Connection property.

How do I change the connection string in Entity Framework?

If you want to change the connection string go to the app. config and remove all the connection strings. Now go to the edmx, right click on the designer surface, select Update model from database, choose the connection string from the dropdown, Click next, Add or Refresh (select what you want) and finish.

Where is Entity Framework connection string?

Right click on your Entity Framework mode (edmx file) > goto Properties. You'll see the connection string there. If your Entity Model is in a separate project, then it must be in it's own settings file.


1 Answers

Just copy the connection string information from your DLL config file to your executable config file.

like image 53
Dean Kuga Avatar answered Sep 20 '22 20:09

Dean Kuga