ASP.NET System.Data.EntityClient connection string help

asp.netconnection-string

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!

Best Answer

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"/>
Related Topic