Geeks With Blogs
Andy Morrison's BizTalk Blog Help, I've fallen and I can't BizTalk!

This post disappeared from a previous blog of mine so I'm reposting it.

---

 

A couple of weeks ago I wrote a short article about an ‘easy’ method of determining the correct BTSNTSvc.exe process to attach to in VS.NET in order to debug orchestration utility components.  Scott Colestock described a better way to determine this here.

 

I liked his method much better than mine but I didn’t want to have Perfmon open whenever I needed to find the correct process id.  I took his suggestion one step further and created a simple console application that writes out the process ids of all started, in-process host instances.  Here are the steps to create (using C#) and use this simple application:

 

  1. Create a new .NET console application.
  2. Add a reference to System.Management.dll
  3. In the class that contains your main() method add using statements for:
    1. System.Diagnostics
    2. System.Management
  4. Add the following code to the main() method:

 

                  //Enumerate all HostInstances of "InProcess" type

                  try

                  {

                        //Create EnumerationOptions

                        EnumerationOptions enumOptions = new EnumerationOptions();

                        enumOptions.ReturnImmediately = false;

 

                        //Search for all HostInstances of 'InProcess' type in the Biztalk namespace scope

                        ManagementObjectSearcher searchObject = new ManagementObjectSearcher("root\\MicrosoftBizTalkServer","Select * from MSBTS_HostInstance where HostType=1 and ServiceState=4",enumOptions);

 

                        //Enumerate through the ManagementObjects and write out the Host Instance Process Ids.

                        foreach(ManagementObject inst in searchObject.Get())

                        {

                              string hostInstanceName = (string)inst["HostName"];

                              PerformanceCounter pc = new PerformanceCounter("BizTalk:Messaging", "ID Process", true);

                              pc.InstanceName = hostInstanceName;

                              float instanceId = pc.NextValue();

 

                              Console.WriteLine(hostInstanceName + ": " + instanceId);

                        }

                  }

                  catch(Exception ex)

                  {

                        Console.WriteLine(ex);

               }

  1. Compile the project.
  2. Add a new External Tool to VS.NET
    1. Open VS.NET, go to Tools, External Tools.
    2. Click Add
    3. Give this tool a Title, I called it ‘BTSHostInstanceProcessIds’
    4. For the Command, browse to the .exe that you just compiled, above.
    5. Check the Use Output Window checkbox.

 

That’s it.  Now when you need to know the process ids for your in-process host instances you can use this tool from the VS.NET Tools window.  Execute it just prior to attaching the debugger.  It will write out the host instance name (actually it is the host instance’s host name) and their process ids to the VS.NET Output window like this:

 

BizTalkServerApplication: 2856

TrackingHost: 4540

 

Posted on Wednesday, December 6, 2006 7:22 AM BizTalk | Back to top

Copyright © Andy Morrison | Powered by: GeeksWithBlogs.net