views:

15

answers:

1

Hi all,

I have a custom workflow implementation what requires updation of an external DB. I created a simple workflow for text purpose and found a strange thing!

my Db update/insert code is placed in a code activity of the workflow. it seems the code activity is executed multiple times when the workflow is invoked on a simple list item in sharepoint custom list. Here is my workflow:

workflow-image

and my code is:

 private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
    workflowProperties.Item["Title"] = "Processed by workflow at "+ DateTime.Now;
    workflowProperties.Item.Update();      

}

private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
    Random rnd = new Random();

    string conStr = "Data Source=192.168.1.57\\TRIBIRD;Initial Catalog=XXXXXX;User ID=XXXXXX;Password=XXXXXXXXXX";
    SqlConnection connection = new SqlConnection(conStr);
    SqlCommand command = connection.CreateCommand();
    command.CommandType = System.Data.CommandType.Text;
    command.CommandText = "INSERT INTO XXXX VALUES(" + rnd.Next() + ",'THE CONTENT FROM SHAREPOINT WORKFLOW','EN',1,1,'BRT')";

    connection.Open();
    command.ExecuteNonQuery();
    command.Dispose();
    connection.Close();
}

in the DB i get more than 1 row for the workflow execution! interesting thing is, during each execution, the number of rows added varies.

Why is this happening? what is my mistake?
Any ideas and suggestions are welcome.

A: 

Make sure you are running the latest patches and updates for SharePoint.

Earlier versions in 2007 would allow cyclic self-triggers (e.g. re-triggering). Later versions do not (but still allow co-cyclic triggers). I suspect this is the problem and a "cascade" is starting by Update method. Just a hunch.

This should be fixed in SP2: Service Pack 2 prevents an on-change workflow from starting itself

pst
@pst.. thanks for the info..any solution to this? my real workflow will have a approval process in between and only after the item is approved, the data is updated/inserted into external DB. any best practice or another solution to this problem?
Abdel Olakara
@Abdel I updated my response with a (hopefully) useful link. If this issue is due to an on-change event, then SP2 should fix the observed behavior. When I have created workflows (that sound) like this I keep the workflow process short and maintain the state in the item itself. Then I go with the assumption that the item WILL NOT BE CHANGED EXTERNALLY while the workflow is running (the workflow itself may change the item, SP2 prevents a re-trigger). With that assumption and the SP2 fix, all works well.
pst
@pst, I did an upgrade and still not working!! i will try to redeploy the workflow again and test...
Abdel Olakara