我在共享服务器上运行ASP.NET MVC,而且我在通过System.Data.EntityClient连接到SQL时遇到问题。下面是我的软管提供商给我连接到SQL的连接字符串以及VS在开发期间为我的本地机器配置的连接字符串,当我部署到服务器时,我的连接字符串应该是什么样的?
来自我的托管服务提供商:
<add name="WeddingsDBEntities"
connectionString="data Source=<server name>; Initial Catalog=<db name>; User ID=<user ID>; Password=<password>;"
providerName="System.Data.EntityClient"/>
来自VS(开发期间):
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"
谢谢!
答案 0 :(得分:8)
您必须将连接字符串包装在格式为
的实体连接字符串中<add name="Name"
connectionString="metadata=<Conceptual Model>|<Store Model>|<Mapping Model>;
provider=<Underlying Connection Provider>;
provider connection string="<Underlying ConnectionString>""
providerName="System.Data.EntityClient"/>
代替:
<add name="WeddingsDBEntities"
connectionString="data Source=<server name>; Initial Catalog=<db name>; User ID=<user ID>; Password=<password>;"
providerName="System.Data.EntityClient"/>
使用此功能:
<add name="WeddingsDBEntities"
connectionString="metadata=res://*/Models.WeddingsModel.csdl|res://*/Models.WeddingsModel.ssdl|res://*/Models.WeddingsModel.msl;provider=System.Data.SqlClient;provider connection string="data Source=<server name>; Initial Catalog=<db name>; User ID=<user ID>; Password=<password>;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient"/>
答案 1 :(得分:1)
将提供程序从entityclient更改为sqlclient(假设代码优先为EF)。
的providerName =&#34; System.Data.EntityClient&#34; /&GT;
到
的providerName =&#34; System.Data.SqlClient的&#34; /&GT;
答案 2 :(得分:0)
<add name="Name" connectionString="metadata=res://*; provider=System.Data.SqlClient; provider connection string='; data source=YOURIP;Initial Catalog=YOURDB;Persist Security Info=True;User ID=YOURUSER;Password=YOURPASSWORD; Connect Timeout=15;Encrypt=False;Packet Size=4096;MultipleActiveResultSets=True'"
providerName="System.Data.EntityClient"/>
Hope this Will help you!!