How do you manage database connections in your ASP.Net application?
My understanding tells me that the "best" way is to open a connection, make a request, close the connection - and do it several times because pooling makes the cost careless.
The problem arises when I have a DAL where each method searches for its own connection. For example.
User x = DAL.GetUserDetails ();
Customer y = DAL.GetCustomer ();
That's fine until we talk about TransactionScope.
using (TransactionScope t ....
{
DAL.UpdateCustomer (y);
DAL.UpdateUser (x);
t.Complete ();
}
ASP.Net wants to use DTC because (I assume) there are several connections.
Someone is going to say "Cache the connection somwhere", but I need to explicitly destroy the connection due to the way I manage security (I execute as / revert), and I do not want you to make a call for each to do this, because that someone will forget to make a call. I could also pass the connection to each method, but this is not ideal, because the page should control the connection.
Do I make sense or have I missed something fundamental here?
source share