Or alternatively should ConnectionStrings.config
just be left up to the server environment and never part of your VS publish?
3 Answers
I would like you to add connection string
in VS, there are a few advantages:
- You can manage connection string of multiple environments like UAT, Prod, Debug, Release
- If you want to add some custom
connection string
then you can also add in that and it will also get published - You can transform
connection string
using SlowCheetah
After the SlowCheetah installation, you need to click Add Transform which will transform connection string config according to your build configuration like Debug, Release, UAT, Prod, etc..
You can create ConnectionStrings.Debug.config.example
file, which will be like below
<?xml version="1.0"?>
<connectionStrings>
<add name="core" connectionString="#{ConnectionString.Core}" />
<add name="master" connectionString="#{ConnectionString.Master}" />
<add name="web" connectionString="#{ConnectionString.Web}" />
</connectionStrings>
So every time when new developer will take code, then they can create own ConnectionStrings.Debug.config
file according to buid configuration and place there connections like below:
<?xml version="1.0"?>
<connectionStrings xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<add name="core"
connectionString="XXX"
xdt:Transform="Replace" xdt:Locator="Match(name)" />
<add name="master"
connectionString="XXX"
xdt:Transform="Replace" xdt:Locator="Match(name)" />
<add name="web"
connectionString="XXX"
xdt:Transform="Replace" xdt:Locator="Match(name)" />
</connectionStrings>
-
Makes sense to me... and I like the idea of the config transforms on
ConnectionStrings.config
much like you'd do with any otherApp.config
orWeb.config
Oct 24, 2019 at 14:48 -
ConnectionStrings get set when you install Sitecore. Where is the benefit of having them in source control?– Richard Seal ♦Nov 14, 2019 at 0:33
Ideally It should not be a part of your VS Publish, it should be left as it is in server. As you have connectionstring.config related to environments not code.
But if you have any custom database used in solution and varies according to environment then you may want to manage it form VS source control then you need to use transform tool like SlowCheetah which will create transform file according to your environment and it has to be configured as per all environment with value specific to respective environment by you.
If you go the link link will provide all information to you for how transform works.
Hope this will help.
I would recommend that you use deploy time replacement to control connection strings. Have a look at how Octopus Deploy does this: https://octopus.com/docs/deployment-process/variables/variable-substitutions
I then have development connection strings checked into source control and use config transforms to add in the token for replacement at deploy time. It's best practice not to include sensitive information in source control, and connection strings fall into this category.