BizTalk: Start EDI batches through SQL Script

Here is the script to start all EDI batches for a given Sender and Receiver Party. the script inserts PAM control messages in database which will trigger EDI batching Orchestration in BizTalk

DECLARE @i int = 47 --start batch Id
WHILE @i <= 80 --end batch id
BEGIN
exec edi_PAMBatchingLogDelete @BatchId=@i,@IgnorePendingControlMessages=0
SET @i = @i + 1
END


INSERT INTO [BizTalkMgmtDb].[dbo].[PAM_Control]
([EdiMessageType]
,[ActionType]
,[ActionDateTime]
,[UsedOnce]
,[BatchId]
,[BatchName]
,[SenderPartyName]
,[ReceiverPartyName]
,[AgreementName])
SELECT 0,
'EdiBatchActivate',
GetDate() as 'ActionDateTime',
0 as 'UsedOnce',
bd.Id,
bd.[Name],
[SenderPartyName],
[ReceiverPartyName],
a.Name
FROM [BizTalkMgmtDb].[tpm].[BatchDescription] bd
join [BizTalkMgmtDb].[tpm].Agreement a on bd.OnewayAgreementId = a.ReceiverOnewayAgreementId

Advertisements
Posted in Misc. Tags: , . Leave a Comment »

Could not load file or assembly ‘Microsoft.BizTalk.Interop.SSOClient, Version=7.0.2300.0

SSO Error

Unexpected exception occurred while configuring [BizTalk EDI/AS2 Runtime].

——————————
ADDITIONAL INFORMATION:

Could not load file or assembly ‘Microsoft.BizTalk.Interop.SSOClient, Version=7.0.2300.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified. (EDIAS2Config)

FIX

Install SSOClient from [BizTalkServer2013 installation media]\BT Server\Platform\SSO\Client

Posted in BizTalk. Tags: . 1 Comment »

BizTalk EDI: Creating batching configuration in code

For outbound EDI batching, we have to create Batch Configuration in Party Configuration and set Filter Criteria about what messages should constitute one batch. But what if Filter Criteria is dynamic or we have too many batches to configure

here is code snippet to create batch configuration through API

 var builder = new SqlConnectionStringBuilder("DATA SOURCE="BTSSQLServer;Initial Catalog=BizTalkMgmtDb;
Integrated Security=SSPI;");
            using (var tmpCtx = TpmContext.Create(builder))
            {
                var agreement = (from p in tmpCtx.Agreements where p.Name == AgreementName select p).FirstOrDefault();
                if (agreement == null)//create agreement if does not exist.
                {
                    string Sender = ConfigurationManager.AppSettings["Sender"] ?? "SenderPartyName";
                    string Receiver = ConfigurationManager.AppSettings["Receiver"] ?? "ReceiverPartyName";
                    var OneWayAgreement = agreement.GetOnewayAgreement(Sender, Receiver); 
                    var firstBatch = OneWayAgreement.GetBatches()[0]; // first batch config is used as template
                    var newBatch = OneWayAgreement.CreateBatch(BatchName);
                    FilterPredicate predicate = firstBatch.GetFilterPredicate();
                    predicate.Groups[0].Statements[0].Value = "FilterRHS";
                    newBatch.SetFilterPredicate(predicate);
                    newBatch.SetReleaseCriteria(firstBatch.GetReleaseCriteria());
                    tmpCtx.AddToBatchDescriptions(newBatch);
                    tmpCtx.SaveChanges();
// this SQL insert is required to Activate the batch config
                    using (var cmd = new SqlCommand(@" INSERT INTO [dbo].[PAM_Control]
                                                                       ([EdiMessageType]
                                                                       ,[ActionType]
                                                                       ,[ActionDateTime]
                                                                       ,[UsedOnce]
                                                                       ,[BatchId]
                                                                       ,[BatchName]
                                                                       ,[SenderPartyName], ReceiverPartyName, AgreementName)
                                                                    SELECT 0 as EDIMessageType
                                                                  ,'EdiBatchActivate' as 'ActionType'
                                                                  ,GetDate() as 'ActionDateTime'
                                                                  ,0 as 'UsedOnce' 
                                                                  ," + newBatch.Id + @" as [BatchId]
                                                                  ,'" + BatchName + @"' as [BatchName], '"+ Sender +@"', '"+
 Receiver +@"', '" + AgreementName + "'", new SqlConnection(builder.ConnectionString)))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }
                tmpCtx.Dispose();
Posted in BizTalk, C#. Tags: , . Leave a Comment »