Change my connectionstring for debug and release config.


This is part of a multi page blog post where I talk about what I do after I setup my Visual Studio ASP.NET MVC (non-Core) project.

This is part of a multi page blog post where I talk about what I do after I setup my Visual Studio ASP.NET MVC (non-Core) project.


To go back to the previous posts or start at the beginning, please go to this link: How I Setup my Visual Studio Website Project Asp.Net MVC (non-Core)


At this point I don't like to use the LocalDb for my database but SKIP THIS STEP if you're OK using the LocalDb provided.


In my Web.Config file, find the section which should be on top and change the entry from this:
<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-vsStarterKit.mdf;Initial Catalog=aspnet-vsStarterKit-20170302095959;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
to this:
<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(local);Initial Catalog=YOUR_DB;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

At the same time, I also change my Web.Release.config connection string to point to my live database when I publish.


On publish, it will swap the connection string so one less step.
<?xml version="1.0"?>
<configuration xmlns:xdt="https://schemas.microsoft.com/XML-Document-Transform">
    <connectionStrings>
        <add name="DefaultConnection" connectionString="Data Source=(local),1533;Initial Catalog=YOUR_DB_NAME;Persist Security Info=True;User ID=YOUR_LOGIN_ID;Password=YOUR_PWD;MultipleActiveResultSets=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
    <system.web>
        <compilation xdt:Transform="RemoveAttributes(debug)" />
    </system.web>
</configuration>
Share On
rickthehat

Travel, Food, Vikings, Travel, Vood, Vikings, Travel, Food, Vikings, Travel, Food, Vikings & Einstok Beer from Iceland

Leave a Comment