HighTechTalks DotNet Forums  

adapter.fill question

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss adapter.fill question in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Tash
 
Posts: n/a

Default adapter.fill question - 03-17-2005 , 12:09 PM






After an adapter is filled using "adapter".fill in vb.net, is the connection
automatically closed after the method binds the dataset ???


Thanks

Reply With Quote
  #2  
Old   
julia
 
Posts: n/a

Default Re: adapter.fill question - 03-18-2005 , 01:50 AM






Hi,

After you are finished with the connection, you should always close it.
You close the connection using the Close method on the Connection property.
Unlike in ADO, where you could wait until the Connection object went
out of scope for the connection to be closed, in ADO.NET you should
always explicitly close the connection. Calling Close() on the Connection
will release the database connection back to the pool for some other
procedure to reuse as soon as possible.

HTH

Mona

"Tash" <Tash (AT) discussions (DOT) microsoft.com> wrote

Quote:
After an adapter is filled using "adapter".fill in vb.net, is the
connection
automatically closed after the method binds the dataset ???


Thanks



Reply With Quote
  #3  
Old   
Tash
 
Posts: n/a

Default Re: adapter.fill question - 03-18-2005 , 09:33 AM



But I'm not making a connection object.

Dim usercnString As String = "data source=ffnynt03;initial
catalog=FF_Directory;password=xxxxx;persist security info=False;user
id=xxxxx;workstation id=RE_Proposed_Matter_Web;packet size=4096"

strUserSQL = "Select (lastname + ', ' + firstname) as FullName from
Directory where userLogin = '" + logon_user + "'" 'SQL Query to get logged on
user full name.

adapterUser = New SqlDataAdapter(strUserSQL, usercnString)
dsUser = New DataSet
adapterUser.Fill(dsUser, "User")

And the adapterUser.fill method makes the connection automatically. Hence my
question does that adapter.fill close the connection after it is binding the
data to the dataset?

Thanks,
Tash


"julia" wrote:

Quote:
Hi,

After you are finished with the connection, you should always close it.
You close the connection using the Close method on the Connection property.
Unlike in ADO, where you could wait until the Connection object went
out of scope for the connection to be closed, in ADO.NET you should
always explicitly close the connection. Calling Close() on the Connection
will release the database connection back to the pool for some other
procedure to reuse as soon as possible.

HTH

Mona

"Tash" <Tash (AT) discussions (DOT) microsoft.com> wrote in message
news:56BF9CAC-843B-414E-964D-1D2CD17B865F (AT) microsoft (DOT) com...
After an adapter is filled using "adapter".fill in vb.net, is the
connection
automatically closed after the method binds the dataset ???


Thanks




Reply With Quote
  #4  
Old   
MonaE
 
Posts: n/a

Default Re: adapter.fill question - 04-06-2005 , 01:33 AM



It is hard to figure out how you can make this work without a Connection
object!
If you are not making one, you must be getting one from somewhere because
the DataAdapter uses a Command object which requires a Connection.

However, to answer your question:
The DataAdapter(DA) leaves the connection in the state in which it was
found. If you open the connection BEFORE you call Fill, the DA will leave it
open. If the connection is closed when you call Fill, the DA will open it,
use it, and close it again.

You should though, use data access code within a try..catch..finally clause.
In the finally clause, you should have a line such as:
if (conn.State != ConnectionState.Closed) { conn.Close(); }
where conn is your connection instance variable.
That way you can be sure that the connection is always closed if it is not
already closed.

"Tash" wrote:

Quote:
But I'm not making a connection object.

Dim usercnString As String = "data source=ffnynt03;initial
catalog=FF_Directory;password=xxxxx;persist security info=False;user
id=xxxxx;workstation id=RE_Proposed_Matter_Web;packet size=4096"

strUserSQL = "Select (lastname + ', ' + firstname) as FullName from
Directory where userLogin = '" + logon_user + "'" 'SQL Query to get logged on
user full name.

adapterUser = New SqlDataAdapter(strUserSQL, usercnString)
dsUser = New DataSet
adapterUser.Fill(dsUser, "User")

And the adapterUser.fill method makes the connection automatically. Hence my
question does that adapter.fill close the connection after it is binding the
data to the dataset?

Thanks,
Tash


"julia" wrote:

Hi,

After you are finished with the connection, you should always close it.
You close the connection using the Close method on the Connection property.
Unlike in ADO, where you could wait until the Connection object went
out of scope for the connection to be closed, in ADO.NET you should
always explicitly close the connection. Calling Close() on the Connection
will release the database connection back to the pool for some other
procedure to reuse as soon as possible.

HTH

Mona

"Tash" <Tash (AT) discussions (DOT) microsoft.com> wrote in message
news:56BF9CAC-843B-414E-964D-1D2CD17B865F (AT) microsoft (DOT) com...
After an adapter is filled using "adapter".fill in vb.net, is the
connection
automatically closed after the method binds the dataset ???


Thanks




Reply With Quote
  #5  
Old   
Ravichandran J.V.
 
Posts: n/a

Default Re: adapter.fill question - 04-08-2005 , 03:07 AM



The connection is managed implicitly by the DataAdapter object. The
connection will be opened and closed by the dataadapter object.

with regards,

J.V.


"Tash" wrote:

Quote:
But I'm not making a connection object.

Dim usercnString As String = "data source=ffnynt03;initial
catalog=FF_Directory;password=xxxxx;persist security info=False;user
id=xxxxx;workstation id=RE_Proposed_Matter_Web;packet size=4096"

strUserSQL = "Select (lastname + ', ' + firstname) as FullName from
Directory where userLogin = '" + logon_user + "'" 'SQL Query to get logged on
user full name.

adapterUser = New SqlDataAdapter(strUserSQL, usercnString)
dsUser = New DataSet
adapterUser.Fill(dsUser, "User")

And the adapterUser.fill method makes the connection automatically. Hence my
question does that adapter.fill close the connection after it is binding the
data to the dataset?

Thanks,
Tash


"julia" wrote:

Hi,

After you are finished with the connection, you should always close it.
You close the connection using the Close method on the Connection property.
Unlike in ADO, where you could wait until the Connection object went
out of scope for the connection to be closed, in ADO.NET you should
always explicitly close the connection. Calling Close() on the Connection
will release the database connection back to the pool for some other
procedure to reuse as soon as possible.

HTH

Mona

"Tash" <Tash (AT) discussions (DOT) microsoft.com> wrote in message
news:56BF9CAC-843B-414E-964D-1D2CD17B865F (AT) microsoft (DOT) com...
After an adapter is filled using "adapter".fill in vb.net, is the
connection
automatically closed after the method binds the dataset ???


Thanks




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
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.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.