Adapter.Dispose

Posts   
 
    
Posts: 40
Joined: 01-Sep-2005
# Posted on: 12-Dec-2005 21:57:54   

We have just moved to Adapters and have seen that we should Dispose after using a Transaction...

Should I dispose after using a Transaction (what does it matter if I do not ?) --- This is probably more of a .net question ---

Should I dispose after using an Adapter (even if I do not use an explicit transaction)

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 13-Dec-2005 02:16:27   

Go ahead and just use this and it will take care of the disposal for you. I believe that disposing is not as necessary with MS SQL, moreso for firebird and oracle.

using (DataAccessAdapter adapter = new DataAccessAdapter()) { adapter.FetchCollection(myCollection, myFilter); // any other code that you use the adapter for }

This will automatically dispose the adapter for you when you are done, you do not need to worry about doing it after any transactions, since when you do it is longer usable.

Posts: 40
Joined: 01-Sep-2005
# Posted on: 13-Dec-2005 04:07:35   

Thanks - I thought that would be the case, but the doc stated Dispose should be called. Thought there must be a reason for this particularly with persisting changes...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Dec-2005 10:31:43   

PaulMckenzie wrote:

Thanks - I thought that would be the case, but the doc stated Dispose should be called. Thought there must be a reason for this particularly with persisting changes...

It's in the docs to encourage people to call Dispose in their code simple_smile Better safe than sorry simple_smile

So if possible, use the 'using' statement.

Frans Bouma | Lead developer LLBLGen Pro