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.
 

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

Back
Top