Geeks With Blogs
Clara's Notes on Technology Notes to me and the world

While preparing a demo on BizTalk 2006 I have learned something important abouthe rules.

I had created a pretty simple policy with two rules. Both of them changed a field in an XML document according to a field in a database. Whenever I tested the policy all went well. I gave a data connection and a file sample as input to the test and both rules did what they were supposed to do. However, once I started using the rules in an orchestration nothing happened!

My first error was the following:

1st. No data connection provided. When rules use data from a database, you need to provide them with a data connection. Otherwise, how will the policy terms be generated?

Ok. I found an article about how to create a fact retriever and proceeded. I read somewhere that a fact retriever was better for data connections because a single connection was used throughout the application, instead of a single connection per orchestration that used the rules. This seemed wise.

Now my rules were firing but they were not working correctly. My second mistake was the following:

2nd. If data is read from a database and you use a fact retriever, the data is only read once! The data field was being read the first time the rules were used. If the database content changed later, this change was not taken into account into the rules.

What I had not realized is that I needed to assert a short-term fact not a long-term fact (here).

  • Short-term fact: A short-term fact is specific to a single execution cycle of the rule engine.
  • Long-term fact: A long-term fact is loaded into memory for use over an arbitrary number of execution cycles.

The way things finally worked for me was by creating the data connection in the orchestration and passing it as a parameter to the rules. This is explained in this kb article. I must add that you will need to put an atomic scope around the expression and call rules shapes, as shown in the picture below. Also, you will have to put the orchestration inside a transaction in order to be able to have an atomic scope inside it.

The code in the first expression shape is the following:

sqlCon.ConnectionString = "Data Source=(local);Initial Catalog=database;Integrated Security=SSPI";
sqlTx = sqlCon.BeginTransaction();
dataCon = new Microsoft.RuleEngine.DataConnection("database", "table", sqlCon, sqlTx);

And in the second


The call rules shape contains two parameters: an xml document (a message) and the data connection.

Posted on Saturday, December 16, 2006 5:14 PM BizTalk | Back to top

Comments on this post: BizTalk Rules: short- and long-term facts

# re: BizTalk Rules: short- and long-term facts
Requesting Gravatar...
Can you please send me the policy xml? I have no idea how to create the rules to receive the DataConnection as a parameter.

Left by Mick on Aug 06, 2008 4:02 AM

Your comment:
 (will show your gravatar)

Copyright © Clara Oscura | Powered by: