I am using DataSet to retrieve data from the Microsoft SQL Server. Do I need to explicitly close the connection (or the underlying SqlDataAdapter automatically closes the connection)?
I always use DataReader (with using), but first time using DataSet -- that's why wondering about best practice. Thanks in advance.
A DataSet
is a disconnected 'view' on the database.
That is, you load the data from the database in a DataSet
(actually, in a DataTable
, which can be put in a DataSet
), and you can close the Connection that you've used to populate the DataTable
or DataSet
.
You can continue to work with the data that is in the dataset. It does not require an open connection to the DB.
In fact, you should close a DB-connection as soon as you don't need any DB access soon. Connections to databases should be short-lived.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With