publish removes web.config connection strings

Jay O'Brien 71 Reputation points
2022-07-21T20:17:18.81+00:00

I recently moved to a new host. Everything is going well except when I publish, my web.config file is changed removing default connection. The original is
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=sql5103.xxxx.net;Database=xxxxx;Integrated Security=False;User ID=xxxxx;Password=xxxx"/>
<add name="CMReportConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\CMReport.accdb" providerName="System.Data.OleDb"/>
<add name="Excel03ConString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}; Extended Properties='Excel 8.0;HDR={1}'"/>
<add name="Excel07ConString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties='Excel 8.0;HDR={1}'"/>
</connectionStrings>

but the web.config file on the host after publishing is

<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="" />
<add name="CMReportConnectionString" connectionString="" providerName="System.Data.OleDb" />
<add name="Excel03ConString" connectionString="" />
<add name="Excel07ConString" connectionString="" />
</connectionStrings>

Developer technologies ASP.NET Other
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-07-22T05:51:12.253+00:00

    Hi @Jay O'Brien ,
    From my point of view,you mean that your Web.config is modified when you public this project,
    I think it may be some content in Web.Debug.config and Web.Release.config under Web.config to be replaced,
    you can show Take a look at your Web.Debug.config and Web.Release.config code, this will give me more information to help you troubleshoot.
    The following documents will help you better learn this knowledge, you can refer to it.
    https://devblogs.microsoft.com/dotnet/asp-net-web-projects-web-debug-config-web-release-config
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Jay O'Brien 71 Reputation points
    2022-07-22T13:49:41.427+00:00

    My Web.Debug.Config is empty .

    Web.Release.config does have RemoveAttributes(debug)

    <?xml version="1.0" encoding="utf-8"?>

    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

    <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />

    </system.web>
    </configuration>

    I commented out <compilation xdt:Transform="RemoveAttributes(debug)" /> and the connection string was still removed


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.