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.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Re: multiple local connections or single connection in database class? by Cor

Cor
Fri Feb 18 07:40:57 CST 2005

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



Re: multiple local connections or single connection in database class? by Paul

Paul
Fri Feb 18 08:20:13 CST 2005

On Fri, 18 Feb 2005 08:33:59 -0500, "John B" <spamfree@hotmail.con> wrote:

¤ 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 ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)

Re: multiple local connections or single connection in database class? by NuTcAsE

NuTcAsE
Fri Feb 18 09:39:29 CST 2005

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