DataAccessAdapter and Dispose()

Posts   
 
    
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 14-Dec-2006 16:38:44   

I'm a bit confused about whether or not I need to call Dispose() after I use a DataAccessAdapter. I see it in the best practices of the help file, and I have seen it mentioned in these forums. But, why does this need to be done? Will the Connection be left open for the lifetime of the app if Dispose is not called (explicitly or with using block)?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 14-Dec-2006 17:06:44   

Depends on your database type. Some providers (like the SqlServer one) clean up after a connection is closed. However oracle, firebird etc. don't do that in that way, you have to call Dispose to make the provider clean up unmanaged resources. An adapter keeps the last created connection object around in a closed state if you call Close(), so a call to that connection's Dispose method is required to get things cleaned up before the GC eventually does this.

So to avoid the trouble, just wrap the dataaccessadapter creation/usage code in a using statement, which automatically calls Dispose() at the end simple_smile

Frans Bouma | Lead developer LLBLGen Pro