There is actually a very important difference between the code that he is
showing and relying on the dataset to open and close the connection for you.
In the code below connection dispose is NOT guaranteed and you will leak a
connection _Every single time_ your adapter fill throws an exception. This
is very bad, please take a look at my blog on leaking connections.
When you rely on the adapter fill method to open and close the connection
for you connection.dispose is _guaranteed_ so there will be no leaks.
--
Angel Saenz-Badillos [MS] Managed Providers
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
I am now blogging about ADO.NET:
http://weblogs.asp.net/angelsb/
"Marina" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> The adapter will close and open the connection if the connection starts
out
> as closed, otherwise it will leave it open.
>
> So it is up to you, if you want to manually open it and close it yourself.
> If you are going to be doing other work with the database, then you should
> open it yourself, do all your work (including getting data through the
> adapter), then close it. If all you are doing is getting data via the
> adapter, then for brevity, you may let it deal with opening and closing
the
> connection. But in the end, this doesn't matter, it's just a matter of
your
> preference.
>
> "jim corey" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I inherited some code that looks like this:
> >
> > mConnection = New OdbcConnection(GetConnectionString())
> >
> > mConnection.Open()
> > mAdapter.SelectCommand.Connection = mConnection
> > 'Can execute reader or execute nonquery
> >
> >
> > mAdapter.Fill(mDataSet, mTable)
> > ...
> > mConnection.Dispose()
> >
> > I've just read here that the adapter will handle the opening and
> > closing of the connections.
> >
> >
>
http://groups.google.com/groups?hl=e...40TK2MSFTNGP12
> >
> > My assumption is that the code above is still just opening one
> > connection, so that's there no real need to change it.
> > Is this correct?
> >
> > TIA,
> > Jim
>
>