Database connection sharing

A

Atif Jalal

How can I share the sane databse connection between asp.net pages. I
also use objects(middleware), so can I pass the same DB connection
when I instantiate the object by calling its constructor?
 
S

Steve C. Orr, MCSD

This connection sharing is done automatically. ADO.NET has built in
connection pooling.
Open your db connection just before you need it, and close it as soon as you
are done with it.
As long as you use the same exact connection string everywhere the sharing
will be automatic - you will not actually open a new database connection
each time despite what the syntax suggests. The connections will be
recycled for you.
Purposely keeping connections open and trying to pass them to other pages
will result in inefficient, poorly performing code.
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top