views:

168

answers:

2

Hi,

I want to perform some logging when a SqlTransaction is committed or rolledback. I see that SqlTransaction class does not expose any such events like OnCommit or OnRollback.

damn! SqlTransaction class is sealed, I cant help it out with inheritance.

Now, what must be the reason they have not allowed these events to happen ?

Is there a way to do these events with SqlTransaction or any such alternate of SqlTransaction that provides ?

Thanks.

A: 

Nope. Nothing built-in on SqlTransaction, nor per command ones on SqlCommand.

Best you can do is wrap this up with your own class that provides the notifications.

Sam Saffron
just edited my question. SqlTransaction is sealed. cant help it.
this. __curious_geek
+1  A: 

One possibility is to create a class that implements IDbTransaction, and wraps an internal SqlTransaction. You would then have to say something like:

IDbCommand icommand = (IDbCommand)command; // Where command is a SqlCommand.
command.Transaction = itransaction; // Class implementing IDbTransaction and wrapping SqlTransaction.

I have not tried this and the above must be considered pseudocode. I'm skeptical it will even work, but it's probably worth a try.

Gregory Higley
Let me try it out and see if it works..
this. __curious_geek