How to release the db resource

  • Thread starter Thread starter Mullin Yu
  • Start date Start date
M

Mullin Yu

Hi,

I'm using DataAdapter, and want to know how to release the database
connection/resource.

if not, i think it may crash my application and system.

my coding is as follow:
OleDbDataAdapter DataAdapter =

new OleDbDataAdapter(

commandString, connectionString);

DataSet DataSet = new DataSet( );

DataAdapter.Fill(DataSet,"OutboundQueueItem");

// Get the one table from the DataSet

DataTable dataTable = DataSet.Tables[0];

DataRow dataRow = dataTable.Rows[0];

lngJobID = (long) dataRow["JobID"];
 
Hi Mullin Yu,

DataAdapter.Fill will open the connection and close it afterwards.
Unless you Open() the connection before calling DataAdapter.Fill(), then
you will have to add the Close() for the connection to close it.

Happy coding!
Morten
 
Also, for good good measure, it doesn't hurt to call Dispose when one is
done with it. There is some additional cleanup that the data adapter does
when Dispose is called.

Hope this helps.
 
Back
Top