Transactions through Remoting

R

Ryan H

Hi,

My data access layer for my VB.NET 1.1 application resides on a different
server and is accessed via Remoting.

Is there a way to configure my data access layer so that I can use
Transactions? For example, I would like to do the following from the client:

Try
DataAccessLayerClass.RunSQL("UPDATE MyTable SET Column3 = "aa", ConnObj,
TransactionObj)
SendEmail()
TransactionObj.Commit
Catch
' Update or sending of email failed
TransactionObj.Rollback
End Try

Any help on how to use Transactions while the data access layer is accessed
via Remoting would be appreciated.
I am also open to rewriting my current code (i.e. change data access
location) if there is an alternative solution.

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Ryan,

This is a really bad design for your data layer for a number of reasons.

First, you are passing sql statements to your data layer. This is
unadvisable, as you should use stored procs instead. Also, if you have to
pass SQL statements, you should at least make sure that you parameterize
them so that you protect yourself against injection attacks.

But that's not the real problem here. Here, you are passing your
connection and transaction object to your data layer. The problem with this
is that those objects both derive from MarshalByRefObject. This means that
a proxy is passed to your data layer and any calls to methods/properties on
the connection/transaction are being made back to your machine.

What you really should be doing is handling this in process. You aren't
gaining anything by sending it to another machine, since you are opening the
connection on yours.

Either that, or have the data layer construct the connection.

However, that doesn't solve the issue you have with managing the
transaction. In reality, you need to make the operation that you are
performing transactional. There are a few ways of doing this.

The first would be to use .NET 2.0 and use the TransactionScope class to
encapsulate the transaction scope. The second would be to create a COM+
component through the classes in the System.EnterpriseServices namespace.

Hope this helps.
 
M

Michael Nemtsev

Hello Ryan,

RH> My data access layer for my VB.NET 1.1 application resides on a
RH> different server and is accessed via Remoting.
RH>
RH> Is there a way to configure my data access layer so that I can use
RH> Transactions? For example, I would like to do the following from the
RH> client:

You need to use Transaction attribute, it available from EnterpriseServices
namespace

RH> Any help on how to use Transactions while the data access layer is
RH> accessed
RH> via Remoting would be appreciated.

AFAIK, there could be a problem if u use COM+, because context that take
a part in DTC can be send across network only via DCOM, not remoting

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
N

Nicholas Paldino [.NET/C# MVP]

Michael,

Using the Transaction attribute won't work outside of COM+, so if he is
going to go this route, he has to go through Enterprise Services.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top