EntityFramework database connection string reuse:
<connectionStrings>
<add name= "Legalentities"
Connectionstring= "
Resource mode, plus file mode
METADATA=RES://*/LEGALDB.CSDL|RES://*/LEGALDB.SSDL|RES://*/LEGALDB.MSL;
Provider=system.data.sqlclient;
Provider Connection string="
Gets the name of the instance of SQL Server to connect to, with a return type of string
Data source=***;
Initial catalog=***;
User id=***;
password=***;
Multipleactiveresultsets=true;
app=entityframework" "
Providername= "System.Data.EntityClient"/>
</connectionStrings>
Create your own entityconnection and pass it on to ObjectContext.
Public Cnblogsobjectcontext ()
: Base (Buildconnection ("Cnblogsdb"), "Club_cnblogscontainer")
{
}
Static EntityConnection buildconnection (String connectionstringname)
{
String connectionString = Configurationmanager.connectionstrings[connectionstringname]. ConnectionString;
MetadataWorkspace workspace = new MetadataWorkspace (new string[] {"res://*/"},
New assembly[] {assembly.getexecutingassembly ()});
SqlConnection SqlConnection = new SqlConnection (connectionString);
return new EntityConnection (workspace, sqlConnection);
}
EntityFramework Database connection string Reuse