using or without using when create a DbCommand ?

Topics: Data Access Application Block
Apr 22, 2011 at 5:51 AM

i aware that some DbCommand embraced by using , but some not when i refered to demo DataAccess project .

Could anyone tell me why?

Apr 24, 2011 at 10:20 AM

Hi,

It’s always a good practice to handle your resources well. Though I couldn’t recall of any samples in DAAB which specifically requires you to do this unless there is really something in your DbCommand that holds it, which require you to dispose them.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Apr 25, 2011 at 2:30 AM

Thanks your response.

i referred to the DataAccess of EntLib Dev Guide RC - Code Samples

some of DbCommands embraced by using , but some not, i want to know why?

i know it 's a good practice to use using when handle IDataReader.

Apr 25, 2011 at 5:16 AM

Honestly, I really don't have an idea why some DbCommands were not wrapped inside the using block. As a best practice, it is encouraged that all objects implementing IDisposable should be wrapped inside using block. This includes DbCommand as it implements IDisposable.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Apr 25, 2011 at 5:19 AM

Thank you very much!