Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET System.Data.EntityClient connection string help

I'm running ASP.NET MVC on a shared server and I'm having problems connecting to SQL via System.Data.EntityClient. Below is the connection string that my hosing provider gave me to connect to SQL and the one that VS configured for my local machine during development, what should my connection string look like when I deploy to the server?

From my hosting provider:

<add name="WeddingsDBEntities" 
  connectionString="data Source=<server name>; Initial Catalog=<db name>; User ID=<user ID>; Password=<password>;" 
  providerName="System.Data.EntityClient"/>

From VS (during development):

connectionString="metadata=res://*/Models.WeddingsModel.csdl|res://*/Models.WeddingsModel.ssdl|res://*/Models.WeddingsModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\WeddingsDB.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"

Thanks!

like image 557
Birdman Avatar asked Mar 28 '09 20:03

Birdman


People also ask

What is EntityClient?

The EntityClient provider is a data provider used by Entity Framework applications to access data described in a conceptual model. For information about conceptual models, see Modeling and Mapping. EntityClient uses other . NET Framework data providers to access the data source.

What is the use of connection string in asp net?

The first connection string, DefaultConnectionString, is used to describe the database that needs to be connected to from ASP.net pages. The second connection string, StandardConnectionString, is used by the Report Control in Report Center.

What is metadata in connection string?

The Metadata parameter contains a list of locations for the EntityClient provider to search for model and mapping files. Model and mapping files are often deployed in the same directory as the application executable file.


2 Answers

You have to wrap the connection string instide an entity connection string which is in the format of

<add name="Name"
  connectionString="metadata=<Conceptual Model>|<Store Model>|<Mapping Model>;
  provider=<Underlying Connection Provider>;
  provider connection string=&quot;<Underlying ConnectionString>&quot;" 
  providerName="System.Data.EntityClient"/>

Instead of:

<add name="WeddingsDBEntities" 
  connectionString="data Source=<server name>; Initial Catalog=<db name>; User ID=<user ID>; Password=<password>;" 
  providerName="System.Data.EntityClient"/>

Use this:

<add name="WeddingsDBEntities"
  connectionString="metadata=res://*/Models.WeddingsModel.csdl|res://*/Models.WeddingsModel.ssdl|res://*/Models.WeddingsModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data Source=<server name>; Initial Catalog=<db name>; User ID=<user ID>; Password=<password>;MultipleActiveResultSets=True&quot;" 
  providerName="System.Data.EntityClient"/>
like image 100
bendewey Avatar answered Oct 06 '22 01:10

bendewey


Change the provider from entityclient to sqlclient (assume code first EF).

providerName="System.Data.EntityClient" />

to

providerName="System.Data.SqlClient" />

like image 20
Tony Trembath-Drake Avatar answered Oct 05 '22 23:10

Tony Trembath-Drake