This article reproduced: http://www.cnblogs.com/dudu/archive/2011/01/29/entity_framework_connection_string.html
The connection string used by the Entity framework is different from ADO, see:
The connection string for the ado.net,entity framework is not only to hold the metadata configuration information, but also to hold the full database connection string (in the "Provider connection string" section).
There are two disadvantages to this design:
1. Connection string configuration is complex;
2. The existing ADO. DB connection string cannot be reused.
I wrote this in the technical promotion: Public classdalbase{ PublicNwentities Nwcontext {Get;Set; } Publicdalbase () {stringProviderString =Configurationmanager.connectionstrings[connectionstringname]. ConnectionString; stringconn =getentityconnstring (providerstring); Nwcontext=Newnwentities (conn); } Private stringGetentityconnstring (stringproviderstring) {Entityconnectionstringbuilder Entitybuilder=NewEntityconnectionstringbuilder (); //The value of the metadata property is pasted from the config generated by the wizard .Entitybuilder.metadata ="RES://*/NW.CSDL|RES://*/NW.SSDL|RES://*/NW.MSL"; Entitybuilder.providerconnectionstring=providerstring; Entitybuilder.provider="System.Data.SqlClient"; returnentitybuilder.tostring (); }}
Note the above Entitybuilder.metadata = "RES://*/NW.CSDL|RES://*/NW.SSDL|RES://*/NW.MSL";
Metadata: Indicates the path of the. CSDL/.SSDL/.MSL three files to match the name of your edmx file.
The Web. config file is as follows:
Entity freamwork configuration file mode
<add name="lgscmsentities"connectionstring="metadata=res://*/model1.csdl|res://*/model1.ssdl|res://*/model1.msl;provider=system.data.sqlclient; Provider Connection string=" server=zengfanlong;database=lgscms;uid=sa;pwd=123456;""Providername="System.Data.EntityClient"/>
Ado. NET mode configuration file <add name="lgscmsentities"connectionstring="server=zengfanlong;database=lgscms;uid=sa;pwd=123456;"/>
Reusing an existing database connection string in the Entity Framework