Client Events and SQL

  • 17 August 2006
  • 4 replies
  • 0 views

Badge +7
Hi All,

I have a client event in my workflow that loads a form for the user to complete.

I obtain the serial number, etc, and all is good. I also, within the same client event, hand the URL for the form + serial number to a process datafield.

I need to write this process datafield to SQL, but I need to do it within the same client event.

Whatever I try, I cannot get this to work.

Can I do a SQL insert within a client event? Or am I barking up the wrong tree?

Many thanks,

Richard

Edit: Here is the code I am trying to compile:

.Value.ToString();
sqlComm.CommandText += strVar ;


OpenConnection(ref sqlConn);

sqlComm.ExecuteNonQuery();

}

catch (System.Exception ex)
{

throw new System.Exception(ex.Message);
}

sqlConn.Close();
K2.Synchronous = true;

}

private void OpenConnection(ref System.Data.SqlClient.SqlConnection SqlConn) {

if (SqlConn.State == System.Data.ConnectionState.Closed) {
SqlConn.Open();
}

}


4 replies

Badge +11
Although I haven't tested it, I cannot see why this would be a problem. You can either do your database manipulation in a separate assembly and just call it from the client event OR use the code behind a 'SQL Data Event' to do the same thing inside the client event code.

The one thing that would concern me a bit though is the fact that you copy the serial number to a process level datafield and store this datafield in a database. Be careful of having more than one destination user. If you have more than one destination user, only the last user's serial number will be uploaded to the database.

Regards,
Ockert
Badge +7
Hi Ockert

Thanks for the continued support, it is appreciated as always.

Using the code behind a "SQL Data Event" is exactly what I'm trying to do. As in the code I posted, I insert it below the code for the client event and it refuses to compile.

It tells me I am missing an assembly or reference??

I did the exact same thing with a list event, and it worked fine....

The reason the link is going into a database is that I want the link to be visible in a dataview webpart. However, there will only ever be one destination user so I don't see that as a problem. However your advice is taken on board.
Badge +7
I resolved the issue.

The code should've looked like this:

.Value.ToString();
sqlComm.CommandText += strVar ;


OpenConnection(ref sqlConn);

sqlComm.ExecuteNonQuery();

}

catch (System.Exception ex)
{

throw new System.Exception(ex.Message);
}

sqlConn.Close();
K2.Synchronous = true;

}

private void OpenConnection(ref System.Data.SqlClient.SqlConnection SqlConn) {

if (SqlConn.State == System.Data.ConnectionState.Closed) {
SqlConn.Open();
}

}



Thanks for the help Ockert.

Maybe this could be considered for the KB? There is a great article in there on combining client and sps list events, but combining a client and sql event was a little more tricky!

Regards,

Rich
Badge +7
Sorry! That should have been:

.Value.ToString();
sqlComm.CommandText += strVar ;


OpenConnection(ref sqlConn);

sqlComm.ExecuteNonQuery();

}

catch (System.Exception ex)
{

throw new System.Exception(ex.Message);
}

sqlConn.Close();


}

private void OpenConnection(ref System.Data.SqlClient.SqlConnection SqlConn) {

if (SqlConn.State == System.Data.ConnectionState.Closed) {
SqlConn.Open();
}

}





I hope that someone finds this useful.

Reply