Database connection sharing

  • Thread starter Thread starter Atif Jalal
  • Start date Start date
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?
 
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.
 
Back
Top