I know there is probably an obvious reason but I can't find it..
I usually use the using
statement during DB connection and data reading, but I can't use it on DataAdapter
because it doesn't implement IDisposable
.
Also: how can it behave after filling a dataset?
Does it close itself the connection?
Only close it or dispose it?
Do I have to dispose the internal connection by myself after the dataset filling? If so, why IDataAdapter
doesn't have a related property/method?
DataAdapter dosn't implement IDisposable because it doesn't have any member variables that need to be handled outside of normal garbage collection. In other words it doesn't need to implement IDisposable.
If your intrested you can see the source code to the Mono DataAdapter here : http://www.java2v.com/Open-Source/CSharp/2.6.4-mono-.net-core/System.Data/System/Data/Common/DataAdapter.cs.htm
In general if you going to close the connection after using it, go ahead in put the connection in a using scope, but its ok too to have a singleton and have multipal DataAdapters in multipal scopes using the same connection.
Hope this makes sense.