how to share the connection?

D

dollar

thanks for your reply Kevin, but I don't understand what do you mean t
"NOT to do that", you mean to declare the same connection and sam
class in every web form ? and what is the built-in connection pooling
please describe it more detail , it is better to show me some simpl
examples, thanks

Kevin said:
Hi dollar,

The best way is NOT to do that. Open and close database connection
as
quickly as possible, and let the built-in Connection Pooling handl
the
rest.

--
HTH,

Kevin Spencer
Microsoft MVP
...Net Developer
What You Seek Is What You Get



-
dolla
 
G

Guest

Hi Dollar,

when you implement your own connection-pooling objects you will have
problems with datareaders still associated with the connection you want to
re-use. In some cases (I don't why) the reader is still attached and active
although you call the Close method of the datareader. So you will have to
check the reader and some PRIVATE members of the connection to detach the
reader (sounds curious but works). But will have the problem that ADO.Net
checks the connection's state every (I guess) 20 seconds. So will have no
benefit :(

The SqlConnection or the underlying object handles pooling by itself. You
can turn that off with your connection-string (pooling=false).

Regards
Patrick


dollar said:
thanks for your reply Kevin, but I don't understand what do you mean to
"NOT to do that", you mean to declare the same connection and same
class in every web form ? and what is the built-in connection pooling ?
please describe it more detail , it is better to show me some simple
examples, thanks

Kevin said:
Hi dollar,

The best way is NOT to do that. Open and close database connections
as
quickly as possible, and let the built-in Connection Pooling handle
the
rest.

--
HTH,

Kevin Spencer
Microsoft MVP
...Net Developer
What You Seek Is What You Get.

 
K

Kevin Spencer

Hi dollar,

What I meant was, do not share a Connection. Open and clase your Connections
as quickly as possible. If they share the same Connection String, they will
be pooled and reused, without your having to do anything special, due to the
built-in Connection Pooling in .Net.

Another way to look at it is this: If you come from an ASP background, and
you're used to having to create and reuse a Connection in order to save
resources used when opening new Connections, you don't have to worry about
that any more. .Net has built-in Connection Pooling that, in a sense,
handles this for you. In fact, it is much safer and better to open and clse
each Connection as quickly as possible. When you close the Connection, you
release it to the Connection Pool. It is not destroyed immediately, but
pooled by the .Net platform.

Does that help?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

dollar said:
thanks for your reply Kevin, but I don't understand what do you mean to
"NOT to do that", you mean to declare the same connection and same
class in every web form ? and what is the built-in connection pooling ?
please describe it more detail , it is better to show me some simple
examples, thanks

Kevin said:
Hi dollar,

The best way is NOT to do that. Open and close database connections
as
quickly as possible, and let the built-in Connection Pooling handle
the
rest.

--
HTH,

Kevin Spencer
Microsoft MVP
...Net Developer
What You Seek Is What You Get.

 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top