dbTalk Databases Forums  

Connecting for entire session, or just when performing an operation?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Connecting for entire session, or just when performing an operation? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Robin Tucker
 
Posts: n/a

Default Connecting for entire session, or just when performing an operation? - 05-05-2005 , 12:30 PM







Here's a simple question for you:

Is it better to maintain a single open connection to the database for the
entire duration of the users session, or to connect, perform an operation
and then disconnect each time the user wants to do some work, within that
session?

If so, why?

Thanks,


Robin



Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Connecting for entire session, or just when performing an operation? - 05-05-2005 , 04:26 PM






Robin Tucker (idontwanttobespammedanymore (AT) reallyidont (DOT) com) writes:
Quote:
Is it better to maintain a single open connection to the database for the
entire duration of the users session, or to connect, perform an operation
and then disconnect each time the user wants to do some work, within that
session?
The normal procedure these days is to do both, That is, typically
your code goes:

cnn.Connect;
cmd = cnn.CreateCommand("SELECT ... ")
cmd.Execute
GetData
cmd.close
cnd.Disconnect

But behind the scenes the client library maintains a connection pool,
so when you say disconnect, the library lingers on the connection, so
if you recnnect within some period, the connection is reused. If you
do connect withine some time, typically 60 seconds, the connection is
closed for real.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


Reply With Quote
  #3  
Old   
shumaker@cs.fsu.edu
 
Posts: n/a

Default Re: Connecting for entire session, or just when performing an operation? - 05-06-2005 , 11:45 AM



It's my understanding that if you use a DataAdapter, that the
DataAdapter makes it appear to you that you're always connected, but
behind the scenes it releases and reqacquires the connection when
appropriate. Does this sound right to anyone?


Reply With Quote
  #4  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Connecting for entire session, or just when performing an operation? - 05-06-2005 , 04:38 PM



(shumaker (AT) cs (DOT) fsu.edu) writes:
Quote:
It's my understanding that if you use a DataAdapter, that the
DataAdapter makes it appear to you that you're always connected, but
behind the scenes it releases and reqacquires the connection when
appropriate. Does this sound right to anyone?
Well, if you have connected explicitly, the DataAdapter will close the
connection. But if the connection is closed, the DataAdapter will open,
perform the operation and close.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.