user2470369
user2470369

Reputation: 167

connection string in database first mvc project

I have created a database first mvc project that gave me a default connection string in my web.config file.

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

Now I need to connect my project to the server database. Connection string:

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

When I change the connection string and run I get the following error:

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.

Upvotes: 0

Views: 2264

Answers (1)

Bas
Bas

Reputation: 27085

Replace the original connection string you had under 'provider connection string' with the new one from the server:

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

Resulting in this connection string:

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

Upvotes: 1

Related Questions