Open SQL 2005 database question

Shoud a SQL 2005 database remain open in a Visual Basic program, or should
it be opened and closed in every subroutine?

Thanks for any info.
Charlie [ Di, 30 Oktober 2007 00:05 ] [ ID #1856896 ]

Re: Open SQL 2005 database question

Charlie wrote:

> Shoud a SQL 2005 database remain open in a Visual Basic program, or should
> it be opened and closed in every subroutine?

How often will the VB program access the database?
Ed Murphy [ Di, 30 Oktober 2007 04:44 ] [ ID #1857732 ]

Re: Open SQL 2005 database question

Charlie (jadkins4 [at] yahoo.com) writes:
> Shoud a SQL 2005 database remain open in a Visual Basic program, or should
> it be opened and closed in every subroutine?

You don't really open or close the database, but you connect and disconnect
from the server.

It's common to do as you say open and disconnect. It's not really cheap to
open a connection to SQL Server. However, the client API maintains a
connection pool, so behind the scenes the connection is open, and is reused
when you connect anew. (If there is no connection for a certain amount of
time, typically 60 seconds, the connection is closed for real.)

Then again, in a two-tier application it's not really any major flaw to
have a global connection that you keep open.


--
Erland Sommarskog, SQL Server MVP, esquel [at] sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx
Erland Sommarskog [ Di, 30 Oktober 2007 09:18 ] [ ID #1857733 ]

Re: Open SQL 2005 database question

Very frequently.

"Ed Murphy" <emurphy42 [at] socal.rr.com> wrote in message
news:4726a8c5$0$11450$4c368faf [at] roadrunner.com...
> Charlie wrote:
>
>> Shoud a SQL 2005 database remain open in a Visual Basic program, or
>> should it be opened and closed in every subroutine?
>
> How often will the VB program access the database?
Charlie [ Di, 30 Oktober 2007 16:21 ] [ ID #1857742 ]
Datenbanken » comp.databases.ms-sqlserver » Open SQL 2005 database question

Vorheriges Thema: Create Index
Nächstes Thema: SqlClient connection to SQL 2005 creates 5000 tcp connections!