As per the Subject line, a very quick question ...
I have code similar to this in various places in my program :
If mySqlConn.State = ConnectionState.Closed Then mySqlConn.Open()
Using mySqlRdr As SqlCeDataReader = mySqlCmd.ExecuteReader()
I've just noticed that although I always Open mySqlConn
... in some places I close MySqlConn
& in some places I close mySqlRdr
... which should I be doing, or should I be doing both ?!?
In the code above, you close both your Connection (explicitly, via teh Close method) and the Readewr (implitly, via the
using block which does a Close and Dispose).
What you should be doing is closing both and (preferably) Disposing both, since they are scarce resources and should not be hogged!
Personally, I use a
using block on the Connection, Command and Reader to be sure.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)