Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top