Re: Best connection management

Tech-Archive recommends: Fix windows errors by optimizing your registry



Miha Markic ha scritto:

so the best solution is always open and close connection for every operation on database? I know that open connection is an expensive operation, so If I need to open and close for every query I have to do can I produce a performance problem?


Not at all. (physicall) connection pooling is working behind the scenes. Performance hit is neglible.


In your case, you have a serious problem - you use a single connection instance (not thread safe) in a multithreaded app (which asp.net is).

I use lock statements to avoid this problem.... Am I wrong?

Yes, you are killing performances. Otherwise not.

All my 3 modules works in a multithread environment so.... if I have in my "dbManager" class a single SqlConnection instance to open and close for every operation could be a good solution? or I need to use a new instance in every "dbManager" method?

Thanks


.



Relevant Pages