Search code examples
asp.net-mvcentity-frameworksomee

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


My existing connection string in web.config looks like:

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

My connection string provided by somee.com is:

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

How should I replace the new connection string with the existing one?


Solution

  • in your web.Release.config add this line on code and publish your project in release mode

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

    please note replace MyDB with your connection string key name. This is called Web.config File Transformations