Transactions with TransactionScope?

  • 25 September 2012
  • 1 reply
  • 3 views

Badge +8

Does K2 have any sort of support for transactions?  K2's best practices recommend minimizing the number and size of data fields stored in a process and storing other data in some other data source (e.g. SQL Server).  That's all well and good, but does K2 support the concept of rolling back a transaction if the process to save my data elements fails?  For example:

using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
{
    try
    {
        using(Connection wfConn = new Connection())
        {
            wfConn.Open(myWorkflowServerConnectionString);
            processInstance = wfConn.CreateProcessInstance(myProcessName);
            ...
            wfConn.StartProcessInstance(processInstance);
        }

        myDatabase.Save(myDbDataFields);

        ts.Complete();
    }
    catch (Exception ex)
    {
        ...
    }
}



I would expect the example above to work since TransactionScope ties into MSDTC, as does K2.  However, K2 support says this won't work.


In the example above, if something fails in the call to myDatabase.Save(), I am left with a K2 process with incomplete data and no way to clean this up.  Even if I use the Workflow Management API to delete the process, if there are notifications at the beginning of that process (e.g. "Thank you for your request"), those notifications have already gone out and I can't recall them.

Conversely, if I call myDatabase.Save() before starting the process instance, I don't have any way to tie the DB record to the process (process instance ID seems the obvious choice, but I don't get that value until after I start the process instance).  The only option seems to be create the DB record, start the process instance, update the DB record with the process instance ID.


Surely there is a better option?


1 reply

Badge +4

Hi,

 

How would I get TransactionScope in C# code??? Which library will help me to get this class?

 

Regards,

Asad Naeem

Reply