Oct 082007

I have need for this occasionally so I thought I would publish the code that I have written.

namespace StottIS.ChangeConfigration { public enum Active { Start, Stop } public class Adapter { public static void RecieveLocationStateChange(string ReceivePort, string ReceiveLocation, Active ActiveFlag) { BtsCatalogExplorer root = new BtsCatalogExplorer(); try { root.ConnectionString = "Server=.;Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;"; //Enumerate the receive locations in each of the receive ports. foreach (ReceivePort receivePort in root.ReceivePorts) { if (receivePort.Name == ReceivePort) { foreach (ReceiveLocation location in receivePort.ReceiveLocations) if (location.Name == ReceiveLocation) { switch (ActiveFlag) { case Active.Start: location.Enable = true; break; case Active.Stop: location.Enable = false; break; default: location.Enable = true; break; } } } } root.SaveChanges(); } catch (Exception e)//If it fails, roll-back all changes. { root.DiscardChanges(); throw e; } } } }

In an orchestration Expression Shape, or in your code outside of BizTalk you simply call this code:

StottIS.ChangeConfigration.Adapter.RecieveLocationStateChange("Password Reset","Password Pickup",StottIS.ChangeConfigration.Active.Stop);

  • Koen

    According to me the following line won’t be called

  • Ryan

    Why won’t it be called? Surely if an exception is thrown, it’ll enter the Catch block and then the DiscardChanges code will be called.

  • Bas

    Hi Eric,

    I think the problem with this code is that you need to be in the BizTalk administrator group to have the required permissions. If you want to run this code in an orchestration, it means you’ll have to add the BizTalk service account to this group, which isn’t the safest thing to do. Do you know any way to avoid the requirement of being in the BizTalk administrators group? Specific database permissions you need to grand or another solution?