PDA

View Full Version : ASP.net database connections...


david7777
03-11-2003, 05:35 PM
I just want to know when i should close the database connection?

ie:

i will read the database, and put the results in a dataset.
(Can i close db connection here?)
Then i want to play with the dataset.
(Or close db connection here?)
Then do i close the dataset after everything or after filling it?

allida77
03-12-2003, 03:23 PM
I guess I didnt see this question yesterday. If you are using the .ExecuteReader() it has a value of CommandBehavior.CloseConnection which closes the connection and data reader on execution:

objCmd.ExecuteReader(CommandBehavior.CloseConnection)

You can always check your current connection state by:

objConn.State.ToString()

Which returns a "Closed" or "Open". A datareader can be tested with :

drFoo.IsClosed.ToString()

Returns True or False.

I usually open and close my connections and in each of my code blocks. Hope this helps.

david7777
03-12-2003, 03:57 PM
That's perfect thanx!

Sadly i never even thought of checking the state of a connection or dataset... So this will help a lot!

Thanx again