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:
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.