Connected Thoughts – Thiago Almeida

October 10, 2007

Performance Counters for new BizTalk Hosts

Filed under: BizTalk — Tags: , , , , , — Thiago Almeida @ 4:28 pm

 Just a quick post about something I ran into after creating new BizTalk hosts on a BizTalk 2006 Server running on Windows Server 2003.

The BizTalk host specific performance counters are available on live monitoring and for you to select to be saved to performance log files a few seconds after the new host and its instance are created and the host instance is started.

 Now here is the gotcha: even though it lets you select the counters for the new host on performance logs, and shows the data on live monitoring, these aren’t going to be saved to log files until the windows service “Performance Logs and Alerts” is restarted on the server.

October 4, 2007

Exporting all applications on a BizTalk group

Filed under: BizTalk — Tags: , , , — Thiago Almeida @ 6:21 pm

 One of the steps I added to the change document at my client where we are separating the high usage applications into their own hosts was that all BizTalk applications should be exported to MSI files before the changes. This way they will have available the most recent version of the applications before any changes are done. We will also export the modified applications after the changes so that the bindings in the MSI files are pointing to the correct host.

 You can export BizTalk applications to MSI files from the BizTalk Server Administration Console, by right clicking on the application and selecting Export -> MSI and then following the different steps of the wizard. This method gives you a lot of flexibility. Another way of exporting an application is by using the BTSTask.exe command line tool with the -ExportApp parameter. This will export the application with the default options you see on the wizard.

Wouldn’t it be nice if BTSTask.exe or the admin console would let you export all applications in a BizTalk group, or let you choose a few to export? Well, just for fun and to save us a few minutes at the client I created a little console application that gets the list of applications and exports them. It uses Microsoft.BizTalk.ExplorerOM.dll to get the list of applications from the management database then loops through them calling BTSTask.exe to perform the export. The app assumes it is running from a computer with BizTalk Server 2006 installed. It accepts two parameters: a connection to the BizTalk management database and the location where the MSI files are going to be created, but they both have default values. This could easily be turned into a windows forms application where the user could choose what applications should be exported.

 Anyways, here is the code:
 

using System;
using System.Reflection;
using Microsoft.BizTalk.ExplorerOM;
using System.Diagnostics;
 
namespace ExportAllBizTalkApps
{
    class Program
    {
        //Build strings with default values
        private static string executableFileName;
        private static string exportLocation;
        private static string connectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI";
 
        static void Main(string[] args)
        {
            try
            {
 
                executableFileName = Assembly.GetExecutingAssembly().Location;
                exportLocation = System.IO.Path.GetDirectoryName(executableFileName);
                connectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI";
 
                if ((args.Length == 1) && (args[0].Contains("?")))
                {
                    ShowHelp();
                    return;
                }
 
                // Command line arguments
                if (args.Length > 0)
                {
                    Array.ForEach(args, SetArgValue);
                }
 
                //Connect to the root
                BtsCatalogExplorer btsCatalog = new BtsCatalogExplorer();
                btsCatalog.ConnectionString = connectionString;
                string commandArguments = "";
 
                //Loop through list of applications
                foreach (Application application in btsCatalog.Applications)
                {
                    //Skip BizTalk.System - It can't be exported
                    if (application.Name != "BizTalk.System")
                    {
                        Console.WriteLine("Exporting Application " + application.Name);
                        //Set arguments for BTSTask.exe
                        commandArguments = "ExportApp -ApplicationName:\"" + application.Name + "\" -package:\"" +
                                       exportLocation + "\\" + application.Name + ".msi\"";
 
                        //Create and start BTSTask.exe process
                        Process p = new Process();
                        p.StartInfo.UseShellExecute = false;
                        p.StartInfo.FileName = "BTSTask.exe";
                        p.StartInfo.Arguments = commandArguments;
                        p.StartInfo.RedirectStandardError = true;
                        p.StartInfo.RedirectStandardOutput = true;
                        p.StartInfo.CreateNoWindow = true;
                        p.Start();
                        //Write result
                        while (p.StandardOutput.Peek() > -1)
                            Console.WriteLine(p.StandardOutput.ReadToEnd());
                        p.WaitForExit();
                    }
                }
 
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error during exports:");
                Console.WriteLine(ex.Message);
            }
 
        }
 
        private static void SetArgValue(string arg)
        {
            //Check first 3 characters
            if (arg.Length > 3)
            {
                switch (arg.Substring(0, 3))
                {
                    case "-c:":
                        connectionString = arg.Substring(3, arg.Length - 3);
                        break;
                    case "-l:":
                        exportLocation = arg.Substring(3);
                        break;
                    default:
                        ShowHelp();
                        throw new Exception("Invalid parameter: " + arg);
                }
            }
            else
            {
                ShowHelp();
                throw new Exception("Invalid parameter: " + arg);
            }
        }
 
        static private void ShowHelp()
        {
            Console.WriteLine("Usage:");
            Console.WriteLine();
            Console.WriteLine("ExportAllBizTalkApps -c:<Connection String> -l:<Export Location>");
            Console.WriteLine("or");
            Console.WriteLine("ExportAllBizTalkApps -?");
            Console.WriteLine();
            Console.WriteLine("Where:");
            Console.WriteLine();
            Console.WriteLine("-? = Returns this usage message.");
            Console.WriteLine();
            Console.WriteLine("-c:<Connection String> = Connection string between double quotes to the BizTalk management database from where the list of applications will be retrieved. Defaults to \"SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI\"");
            Console.WriteLine();
            Console.WriteLine("-l:<Export Location> = The folder where the MSI files are going to be created. Optional, defaults to the location of the executable.");
            Console.WriteLine();
            Console.WriteLine("Examples:");
            Console.WriteLine("ExportAllBizTalkApps -l:c:\\ExportedMSIs");
            Console.WriteLine("ExportAllBizTalkApps -l:\"c:\\Program Files\\Microsoft BizTalk Server\\ExportedMSI\"");
            Console.WriteLine("ExportAllBizTalkApps -c:\"SERVER=MyBizTalkSQLTestServer;DATABASE=TESTBizTalkMgmtDb;Integrated Security=SSPI\"");
            Console.WriteLine();
        }
    }
}

October 1, 2007

BizTalk 2006 R2 RFID links

Filed under: BizTalk, RFID — Tags: , , , , , — Thiago Almeida @ 9:30 am

Microsoft BizTalk 2006 R2 RFID is starting to gather momentum on the internet. Anush Kumar from the Microsoft team manages a great blog on the subject. His latest post mentions two other blogs that are a “must subscribe to”:

-Kalyan, also from Microsoft RFID, with sample code and in-depth coverage of the technology in BizTalk, and

-Mick from across the Tasman in Australia, who has just posted sample code for the DPL RFID reader.

Another couple of great posts on the subject are Matt Meleski’s “BizTalk R2 RFID and working with a real Reader Device (Phidget)”, and Irvin de la Cruz’s “BizTalk RFID Device Provider (DSPI) for DLP Design Hardware”.

To finish off the list, of course I have to include Microsoft’s dedicated forum on the subject – MSDN BizTalk RFID forum – and Microsoft’s homepage on BizTalk RFID.

Let me know if I missed any!

Blog at WordPress.com.