0

我创建了一个数据库优先 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=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\BETADB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;"  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.
4

1 回答 1

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=&quot(your connection string here)&quot;"  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=&quot;Server=tcp:*******,1433;Database=******;User ID=******;Password=******;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=true&quot;"  providerName="System.Data.EntityClient" />
于 2013-07-18T11:20:46.870 回答