I have a general use SQL utility class I wrote for a lot of tasks and I use the SQLInfoMessageEventHandler to display Error/Information messages from long running stored procedures.
I'd like my event handler delegate (which is defined outside the class) to be able to get extra information such as the string storedProcedureName. Is there a clean way to do this?
I have multiple utility classes that I'm trying to keep separate so I don't to display any messages from within the SQL class as I use a different class to display/log events.
I've seen some pretty clever methods on here using Lambda expressions but I can figure out how to make it work when I define the delegate outside my class.
Thanks!
//SQL class method
executeQuery (string storedProcedureName, SqlnfoMessageEventHandler eh = null)
{
//setup SQL connection
if (eh ! null)
{
connection.FireInfoMessageEventOnUserErrors = true;
connection.InfoMessage += eh;
}
//finish work
}
//Outside SQL class
static void showInfoMessage (object sender, SqlInfoMessageEventArgs e)
{
//Display e.Message
//Would also like to receive the storeProcedureName string
}
Aucun commentaire:
Enregistrer un commentaire