0

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?

  • 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. – Mark Gibbons May 7 at 21:32
  • @MarkGibbons i will consider creating seperate Api service thanks for your reply – SitecoreNoob May 8 at 8:51
7

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>
  • 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 – SitecoreNoob May 7 at 14:04
  • Edited detail above – Swati Gupta May 7 at 17:45
  • 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 – SitecoreNoob May 15 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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