在 somee.com 上部署数据库以及如何更新 web.config 中的连接字符串(已发布代码)后,当我使用 Entity Framework 时?

After deploying database on somee.com and how to update connection string in web.config (published code), when I am using Entity Framework?

我在 web.config 中的现有连接字符串如下所示:

<connectionStrings>
    <add name="SampleBloggingDbEntities" 
         connectionString="metadata=res://*/SampleDBModel.csdl|res://*/SampleDBModel.ssdl|res://*/SampleDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=My_System;initial catalog=SampleBloggingDb;persist security info=True;user id=sa;password=somepassword;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />
</connectionStrings>

我somee.com提供的连接字符串是:

workstation id=SampleBloggingDb.mssql.somee.com;packet size=4096;user id=some_id_SQLLogin_2;pwd=somepassword;data source=SampleBloggingDb.mssql.somee.com;persist security info=False;initial catalog=SampleBloggingDb

我应该如何用现有的连接字符串替换新的连接字符串?

在您的 web.Release.config 代码中添加这一行并以发布模式发布您的项目

<connectionStrings xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <add name="MyDB" connectionString="workstation id=SampleBloggingDb.mssql.somee.com;packet size=4096;user id=some_id_SQLLogin_2;pwd=somepassword;data source=SampleBloggingDb.mssql.somee.com;persist security info=False;initial catalog=SampleBloggingDb" xdt:Transform="Replace" xdt:Locator="Match(name)" />
</connectionStrings>

请注意将 MyDB 替换为您的连接字符串键名。 这叫做Web.config File Transformations