Open connections as you need them and close them immediately.
Connection pooling holds onto the physical connection even after
you've closed it. From your comments, I "believe" you think
each time you open and close a connection, you are going through
the expensive connect process. You aren't.
As an example. Let's say you needed to walk across the
room and pick up a piece of paper. If you had to do this
ten times, you'd get tired.
Think of connection pooling as someone who will stand
beside you and will hold the pieces of paper while you
are busy. Then, when you need a piece of paper, it quickly
hands it to you and takes it back when you are done.
When it thinks you no longer need the piece of paper, it
will walk across the room and put the paper back.
Kind of a cheesy example but you get the idea...
--
Robbe Morris [Microsoft MVP - Visual C#]
..NET PropertyGrid Control - ListBox, ComboBox, and Custom Classes
http://www.eggheadcafe.com/tutorials...d-control.aspx
"Hornet77" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>