Connection approch with sql server

  • Thread starter Thread starter RA
  • Start date Start date
R

RA

Hi

I am developing asp.net app using ado.net to access sql server 2000. I am
interested to know which will be the best way to open database connection.
Currently I have connection opens per web form request. Are there better
ways?

Thanks,
Ron
 
Hi,

You should have the connection open for minimum time.
Open it just before db operation and close it as soon as you don't need it
anymore.
There is no penality since the connections are normally (unless otherwise
specified) pooled.
 
Ron,

Usually the best approach is to open the connection just before use, then
close it again before you do any other processing on the web form. ADO.NET
will pool the connection for you by default, so the overhead of opening and
closing the SqlConnection object a request is minimal.

Eric
 
In addition to Eric and Miha' suggestions, you need to
ensure that your connection string is identical for
connection pooling to work. If you build a unique
connection string for each request (e.g., with unique user
id and password based on the user), you can't reuse the
connections.

Donald Xie
 
Back
Top