In order to handle users and their roles/privileges, I'm creating a little library (DLL). The idea is to be able to alter users, roles, etc. by adding this dll to an MVC project. A SQL database houses all of the data.
To access data, I'm using entity framework.
As a result, I provide a new RoleManager—the primary class in the library I'm creating—the following connectionString when I create it:
RoleManager roleManager = new RoleManager(string connectionString);
the following within the constructor:
db = new RoleManagerEntities(connectionString); //This is the EntityFramework
I'm also attempting to provide 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'"
I also see 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 query is the result of my attempt to instantiate the EF from my new project without providing a connection string or anything for it to default to in my app configuration. Shame I can't erase it right now.
Simply transfer the connection string data from the DLL configuration file to the executable configuration file.
The issue is that you are essentially attempting to create a ObjectContext via this Constructor for objects context (String) without giving the string argument in its intended format.
What you must do is as follows:
1. Make an item in your "test project" app.config first since there is where the CLR will go to discover the connection string when it is needed.
<configuration> <connectionStrings> <add name="RoleManagerEntities" connectionString="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'" /> </connectionStrings> </configuration>
db = new RoleManagerEntities("name=RoleManagerEntities");