all groups > dotnet academic > march 2005 >
You're in the

dotnet academic

group:

adapter.fill question


adapter.fill question Tash
3/17/2005 9:09:14 AM
dotnet academic: After an adapter is filled using "adapter".fill in vb.net, is the connection
automatically closed after the method binds the dataset ???


Re: adapter.fill question Tash
3/18/2005 6:33:16 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


[quoted text, click to view]
Re: adapter.fill question julia
3/18/2005 12:20:32 PM
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

[quoted text, click to view]

Re: adapter.fill question MonaE
4/5/2005 10:33:01 PM
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.

[quoted text, click to view]
Re: adapter.fill question Ravichandran J.V.
4/8/2005 12:07:03 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.


[quoted text, click to view]
RE: adapter.fill question Roopesh Rajendiran
5/10/2005 12:18:01 AM
hai,
before u call fill the adapter u call the connection open fuction after
geting data u should call the close connection fuction. becouse adapter is an
abstraction between database and dataset.in dot net we r using disconnected
data architecture so connection is not opened allthe time

[quoted text, click to view]
AddThis Social Bookmark Button