views:

59

answers:

4

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....Thanks for your help

A: 

The constructor might be looking for a connection string in the connectionStrings setting of your web.config with the name that you pass it as the parameter.

So if you call:

db = new RoleManagerEntities("Foobar");

It is looking for:

I'm not positive that this is the solution but that's what the error message seems to indicate.

Dismissile
"Format of the initialization string does not conform to specification starting at index 0." Error
Blankasaurus
A: 

I am not an expert on EF, but I don't think that connection string is valid. Try:

metadata=res://*;provider=System.Data.SqlClient;provider connection string='Data Source=localhost;Initial Catalog=Login;Integrated Security=True;Connection Timeout=60; multipleactiveresultsets=true'
Phil Sandler
Format of the initialization string does not conform to specification starting at index 0.
Blankasaurus
however, if I use "provider connection string='Data Source=localhost;Initial Catalog=Login;Integrated Security=True;Connection Timeout=60; multipleactiveresultsets=true'" then it says it requires metadata...
Blankasaurus
Try my updated answer?
Phil Sandler
"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid."
Blankasaurus
+2  A: 

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

kzen
I did. And this is what happens. "The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid."
Blankasaurus
Nevermind - this works, my error was coming from somewhere else. =/
Blankasaurus
+1  A: 
Morteza Manavi
This is right and good advice. Thanks.
Blankasaurus