开发者

Repeated execution of code activity in SharePoint workflow?

I have a custom wor开发者_运维问答kflow 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:

Repeated execution of code activity in SharePoint workflow?

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜