Biztalk Server SQL Adapter: Understanding Updategrams
Hi! Today I´m going to talk about updategrams when using SQL Adapter as an alternative to send a message!
The SQL Send Adapter supports two choices for sending messages: Updategrams or Stored Procedures.
An updategram is a formatted XML fragment made up of several blocks. Each of these blocks serves a specific purpose. It is the arrangement of these blocks that determines whether the updategram will insert, update, or delete the record. The basic structure of the updategram is shown here:
<root> <sync> <before> <TableName col1="value" col2="value" …/> </before> <after> <TableName col1="value" col2="value" …/> </after> </sync> </root>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
-
The <before> block is used to describe the actual state of the rows. It acts like a WHERE clause.
- The <after> block is used to describe the new state of the rows. It acts like a WHERE clause.
- The <sync> block is a container for the <before> and <after> blocks. It also represents a transactional unit.
It is possible to have more than one <before> and <after> blocks within a <sync> block. In this case the whole operation is transactional. It is also possible to have more than one <sync> block, thus allowing independent transactions.
How do you specify if the updategram will insert, update or delete records?
The answer to this question as I mentioned earlier is the order of the <before> and <after> blocks:
-
When a message appears with only an <after> block, and no corresponding <before> block, the updategram performs an insert operation
-
When a message appears with only a <before> block, and no corresponding <after> block, the updategram performs a delete operation
-
When a message contains both a <before> and a corresponding <after> block, the updategram performs an update operation
In this figure there is an updategram example for each operation:
Figure (a) shows a schema for inserting rows in Customer table. The columns for this type of row are CustomerId, Surname, Name and DocumentNumber.
Figure (b) shows a schema for updating rows in Customer table. The columns to be updated are surname, name and documentNumber and the where condition involves the customerId.
Figure (c) shows a schema for deleting rows in Customer table. The where condition involves the column customerId.
Although in the example I have a separate updategram for each operation, this can be combined within the same updategram to perform more complex operations!
Posted in Biztalk Server 2004 & 2006 |
No Comments »