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] "Tash" wrote:
> 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@discussions.microsoft.com> wrote in message
> > news:56BF9CAC-843B-414E-964D-1D2CD17B865F@microsoft.com...
> > > After an adapter is filled using "adapter".fill in vb.net, is the
> > > connection
> > > automatically closed after the method binds the dataset ???
> > >
> > >
> > > Thanks
> >
> >