BizTalk Tips & Things

Agustin Mantaras BizTalk Blog

How to Stop a BizTalk application programmatically

 

With this method you will be reproducing the same actions than doing this through the BizTalk administration console.

Create a C# .NET Console application (vbs can be used as well) and add a reference to the following DLL:

C:\Program Files (x86)\Microsoft BizTalk Server 2006\Developer Tools\Microsoft.BizTalk.ExplorerOM.dll

Warning

This assembly only works under x86 therefore you will need to compile your console application for x86 environment if running under x64.

 

The Code

Inside the Main method paste the following:

Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer btsCExp= new Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer();

btsCExp.ConnectionString = "server=DatabaseServerContainingTheBizTalkMgmtDb;database=BizTalkMgmtDbName;Integrated Security=SSPI";

Microsoft.BizTalk.ExplorerOM.Application app = btsCExp.Applications["ApplicationNameYouWantToRestart"];

app.Stop(Microsoft.BizTalk.ExplorerOM.ApplicationStopOption.StopAll);

btsCExp.SaveChanges();  //commit the changes

Console.ReadKey();  //this is no needed. Just for debugging purposes. You can erase it

 

Download a Example code

it is a Visual Studio 2013 Project. It has been tested only with BizTalk 2013R2.

This Console application expects arguments. 4 arguments (as you can see in the Debug Section)

  1. ApplicationName is the BizTalk Application name.
  2. SQLServerInstance is the name of the SQL server instance holding the Administration database.
  3.  Action Only start or Stop actions are accepted.
  4. Name of the BizTalk Administration database. If missing the default name will be used.

 

 image

 

You can download it from MSDN Code gallery here

Enjoy Sonrisa