We have an interesting setup where we have SqlTransactions persisted to Application memory on a web application. We're looking into moving our web application into an NLB scenario, so we need a way for those Transactions to not be tied to a single machine's memory. Is there any way we can accomplish this..I've tried serializing a SqlTransaction and a SqlCommand, neither seem to work. Do I need to start looking into the System.Transactions namespace?
I don't believe this can work. Transactions are designed to be temporary and local.
edit
Maybe "transient" is a better word than "temporary".
It makes no sense to store a SqlTransaction
in Application
state. A transaction should not span a single request.
I will assume that you know that Application
state is shared by all users.
Why did you use Application
state instead of Session
state? Session
can work across load balancers, either using the State Server, or SQL Server forms of session persistence.
You may want to take a look at the Distributed Transaction Coordinator. I haven't personally used it for handling transactions across multiple requests, but that's its purpose. The link is the developer's guide for COM and Win32. Here's a tutorial that I think may help you get started on the .NET side of things.
I haven't done this kind of thing before, but SqlTransaction has a CreateObjRef method, which returns an ObjRef, which is serializable. And ObjRef seems to be what you are supposed to mashal back and forth.
Firstly serialization is only meant to be used to capture a snapshot of values/value types-sstudf like strings numbers etc. A transaction is something that is "alive" fir short period of time ( timeouts) for a specific user, with x resour es( typically connections to the database). Since these things are constantly changing serislizing and then restoring them would really screw things up if it were possible, as lots of things would have changed and you would have chaos.
If transactions were meant to be serializable they would have implemented the interface, what you are asking for is just plain bad/dumb.