471,318 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

Re: WCF & Transactions

Hello,

I have one BLL object X with method Y. Inside method Y (*) I call
DAL object(s).

Operation Y can include more then one DAL object (dalObj1.Write,
dalObj2.Write) so I create some kind of "token" with sql connection
reference and pass it to DAL object(s) involved in operation Y (**).

At some point in time (ambient) transaction will finish (with success or
failure) and emit TransactionCompleted event.

I am asking if I can grab that token reference with sqlconnection
reference in TransactionCompleted eventhandler and close connection
without side effects and problems?
(*) call(s) to DAL object(s) is/are inside transaction scope which is
configured to use ambient transaction

(**) I know that it is possible to write this code with "(using
SqlConnection) { write db }" inside each DAL object write method and
don't bother with connection closing problem but this will result in
distributed transaction (because I open N connections to the same SQL
server). Am I correct?

I hope explanation is better this time :)
Alvin Bruney [ASP.NET MVP] wrote:
Sorry for misunderstanding you. I don't understand what you are doing.
You seem to be sharing one connection object with clients as opposed to
object pooling a connection object among clients. There's a huge
difference here if I've understood you correctly. I don't know what the
behavior would be at this point.

To your design point, you shouldn't be passing opened connection around
because you place the closing responsibility on the caller - caller
doesn't have to honor it which implies a resource leak. The better
pattern is to grab the data from the connection, close the connection,
and return the data in a custom business object inside your DAL. There's
no possibility of a resource leak in that pattern.
Jun 27 '08 #1
1 1281
You can do it this way, bear in mind that, according to the docs, your way
of hooking up to transactioncompleted events cause performance issues.

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
-------------------------------------------------------
"No Name" <my************@mail.comwrote in message
news:#m**************@TK2MSFTNGP04.phx.gbl...
Hello,

I have one BLL object X with method Y. Inside method Y (*) I call
DAL object(s).

Operation Y can include more then one DAL object (dalObj1.Write,
dalObj2.Write) so I create some kind of "token" with sql connection
reference and pass it to DAL object(s) involved in operation Y (**).

At some point in time (ambient) transaction will finish (with success or
failure) and emit TransactionCompleted event.

I am asking if I can grab that token reference with sqlconnection
reference in TransactionCompleted eventhandler and close connection
without side effects and problems?
(*) call(s) to DAL object(s) is/are inside transaction scope which is
configured to use ambient transaction

(**) I know that it is possible to write this code with "(using
SqlConnection) { write db }" inside each DAL object write method and don't
bother with connection closing problem but this will result in distributed
transaction (because I open N connections to the same SQL server). Am I
correct?

I hope explanation is better this time :)
Alvin Bruney [ASP.NET MVP] wrote:
>Sorry for misunderstanding you. I don't understand what you are doing.
You seem to be sharing one connection object with clients as opposed to
object pooling a connection object among clients. There's a huge
difference here if I've understood you correctly. I don't know what the
behavior would be at this point.

To your design point, you shouldn't be passing opened connection around
because you place the closing responsibility on the caller - caller
doesn't have to honor it which implies a resource leak. The better
pattern is to grab the data from the connection, close the connection,
and return the data in a custom business object inside your DAL. There's
no possibility of a resource leak in that pattern.
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Alexander Ross | last post: by
5 posts views Thread by princevejita1 | last post: by
7 posts views Thread by simon | last post: by
1 post views Thread by Jim Bancroft | last post: by
3 posts views Thread by Lada 'Ray' Lostak | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.