17 November 2013

Connection not found in the configuration exception

Problem:
I have a MVC 3 application which talks to Business Layer to get the Business objects that paint my UI. Client application consumes Business layer to pull the data from database and business library have one entity framework object. The connection string is added to app.config in connection string section, but when I want create new entity context and use this connection string, this error is appear:
“The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.”
Solution:
You need to copy the connection string in the app.config to your web.config, or copy the entire file to the project which displays the output. It is one of the conditions to consume the framework.

   1:    <connectionStrings>
   2:      <add name="ADONETEntities" connectionString="metadata=res:
//*/Customer.csdl|res://*/Customer.ssdl|res://*/Customer.msl;
provider=System.Data.SqlClient;provider connection string=&quot;
data source=DatabaseTest,10501\SQLEXPRESS;initial catalog=dbTest;
persist security info=True;user id=user_dbo;password=pwd123;
multipleactiveresultsets=True;App=EntityFramework&quot;
" providerName="System.Data.EntityClient" />
   3:    </connectionStrings>

No comments: