2

We are using Sitecore 9.0.x on Azure PaaS

We need to create a custom database for some of our application flows, we intend to use Entity Framework Database first with API controllers for our CRUD operations.

We are using Helix based architecture,As our applcation is hosted on Azure PaaS , i do not intend to disturb or source control the ConnectionStrings.config file , how can I patch only the custom database connection string from my source control, whats is the ideal approach to achieve this?

2
  • I have seen this done before and it isn't a good idea as it tightly couples the platform to the custom database. Instead I would recommend creating a separate WebApi website that has the ef project. Commented May 7, 2019 at 21:32
  • @MarkGibbons i will consider creating seperate Api service thanks for your reply Commented May 8, 2019 at 8:51

1 Answer 1

8

You can install SlowCheetah in your application, you can find link from here

After the installation you need to click Add Transform which will transform connection string config according to your build configuration like Debug, Release, UAT, Prod etc..

In that transform file, you can patch connection string like below code:


<connectionStrings xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <add name="customDBName"
       connectionString="Data Source=XXX;Initial Catalog=XX;User ID=XX;Password=XX"
       xdt:Transform="Replace" xdt:Locator="Match(name)" />   
</connectionStrings>

EDIT

In your case as you do not want to disturb connection string, below code can be possibly solution:

ConnectionStrings.config

<?xml version="1.0"?>
<connectionStrings>
<!-- Keep your all Sitecore connectionString as it is -->
   <add name="core" connectionString="Data Source=XXX;Initial Catalog=XXX;User ID=XXX;Password=XXX" />
  <add name="master" connectionString="Data Source=XXX;Initial Catalog=XXX;User ID=XXX;Password=XXX" />
  <add name="web" connectionString="Data Source=XXX;Initial Catalog=XXX;User ID=XXX;Password=XXX" /> 
 <!-- Add your custom connectionString -->
  <add name="customDBName" connectionString="#{ConnectionString.customDBName}" />   
</connectionStrings>

ConnectionStrings.Debug.Config

<?xml version="1.0"?>
<connectionStrings xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <add name="customDBName"
       connectionString="Data Source=XXX;Initial Catalog=XX;User ID=XX;Password=XX"
       xdt:Transform="Replace" xdt:Locator="Match(name)" />   
</connectionStrings>
3
  • thanks for your reply , i do not intend to source control the entire connectionstring config file , i want to patch only the custom database config file , how can i do this ? , i have updated the Question Commented May 7, 2019 at 14:04
  • Edited detail above Commented May 7, 2019 at 17:45
  • 1
    connection strings in entity framework are stored in Web.config , as we cannot cannot connection string in web.config , how can we use entity framework with sitecore Commented May 15, 2019 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.