我创建了一个数据库第一个mvc项目,它在我的web.config文件中为我提供了一个默认的连接字符串。
<add name="name" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\BETADB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
现在我需要将我的项目连接到服务器数据库。连接字符串:
<add name="name" connectionString="Server=tcp:*******,1433;Database=******;User ID=******;Password=******;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
当我更改连接字符串并运行时,我收到以下错误:
Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.
答案 0 :(得分:1)
将“提供商连接字符串”下的原始连接字符串替换为服务器中的新连接字符串:
<add name="name" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="(your connection string here)"" providerName="System.Data.EntityClient" />
导致此连接字符串:
<add name="name" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:*******,1433;Database=******;User ID=******;Password=******;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=true"" providerName="System.Data.EntityClient" />