multiple local connections or single connection in database class?

multiple local connections or single connection in database class?

Post by John » Sat, 19 Feb 2005 22:33:59


Is is better to:

(1) Have a single connection object in a database class which is
instantiated when first used at start-up and used by other classes (opened
and closed as necessary - NOT kept open).

or

(2) Local variable connections created in the function in which they are
used (and maybe reference the connectionstring in the database class)?



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.yqcomputer.com/ The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
 
 
 

multiple local connections or single connection in database class?

Post by Cor Ligthe » Sat, 19 Feb 2005 22:40:57

John,

There is in this in my opinon no better, just think how much you have to
type (correct by a change) for your solutions and than you know the answer.

Just my thought,

Cor

 
 
 

multiple local connections or single connection in database class?

Post by Paul Cleme » Sat, 19 Feb 2005 23:20:13


Is is better to:

(1) Have a single connection object in a database class which is
instantiated when first used at start-up and used by other classes (opened
and closed as necessary - NOT kept open).

or

(2) Local variable connections created in the function in which they are
used (and maybe reference the connectionstring in the database class)?

Requirements can vary depending upon the type of application and database you are working with, but
the general recommendation is to open (and close) connection objects on an as needed basis rather
than attempt to maintain any type of single persistent and/or global connection.


Paul ~~~ XXXX@XXXXX.COM
Microsoft MVP (Visual Basic)
 
 
 

multiple local connections or single connection in database class?

Post by NuTcAs » Sun, 20 Feb 2005 00:39:29

The first option, which tough seems very easy and less code to wirte,
might start giving you problems on the multi threaded client, service
or an ASP.Net app being accessed by multiple user. If you use one
connection object that is being re-used by many functions, in a multi
threaded enviroment you could have synchronizing issues. Id suggest (2)
using a shared connection string.

NuTcAsE