rick graner dot com

developers! developers! developers!
musings of my creative and technical writing

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.

To go back to the previous posts or start at the beginning, please go to the links below:

  1. 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:

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

to this:

        <add name="DefaultConnection" connectionString="Data Source=(local);Initial Catalog=YOUR_DB;Integrated Security=True" providerName="System.Data.SqlClient" />

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">
        <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)"/>
        <compilation xdt:Transform="RemoveAttributes(debug)" />

Step #3 – Coming Soon