Thursday, 5 November 2015

Asserting Database Facts Per Environment

I've recently been using database facts in Biztalk Business Rules Engine and this has required an assertion of the connection string into the policy which includes the database server/instance, database name, and table name. The database name and table are likely to be static for the life of the application but the database server needs to change based on which environment we have deployed to. I've been considering where to set the configuration for this. The options are:

  • BTSNTSVC config. A per server configuration is possible in this but I think it's best to avoid using such a file.
  • Business rule policy which determines the local machine name then sets the database server based on this. A bit overkill.
  • Business rule vocabulary with static value we can use. Doesn't work too well for different environments.
  • Fact Retriever which will pull the value from somewhere else.
Considering that the database being used is on the same server/instance as the Biztalk databases, I opted to use the Fact Retriever to pull the database/instance configuration from the windows registry.

using System.Data.SqlClient;
using Microsoft.RuleEngine;
using Microsoft.Win32;
namespace My.BRE
    public class AssertSiteConverterDB : IFactRetriever
        public object UpdateFacts(RuleSetInfo ruleSetInfo, RuleEngine engine, object factsHandleIn)
            object factsHandleOut;
            if (factsHandleIn == null)
                object servObj = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\BizTalk Server\\3.0\\Administration", "MgmtDBServer", ".");
                SqlConnection SQLConn = new SqlConnection("Data Source=" + servObj.ToString() + ";Initial Catalog=SIP;Integrated Security=SSPI;");
                DataConnection RulesConn = new DataConnection("my database", "my table", SQLConn);
                factsHandleOut = RulesConn;
                factsHandleOut = factsHandleIn;
            return factsHandleOut;

Gac this and configure your policy to use this Fact Retreiver and this will ensure that the correct database/instance will be asserted no matter which environnment you deploy to.

No comments:

Post a Comment