ASP.NET System.Data.EntityClient connection string help

99封情书 提交于 2019-12-28 23:49:29

问题


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!


回答1:


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



回答2:


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

providerName="System.Data.EntityClient" />

to

providerName="System.Data.SqlClient" />



来源:https://stackoverflow.com/questions/693499/asp-net-system-data-entityclient-connection-string-help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!