I created the following method:
public System.Data.OleDb.OleDbDataReader GetReader(string sqlQuery) { System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(); LoadConnectionStrings(); myConnection.ConnectionString = ConnectionString; myConnection.Open(); System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand(sqlQuery, myConnection); System.Data.OleDb.OleDbDataReader myReader = null; myReader = myCommand.ExecuteReader(); return myReader; }
Several thousand lines of code rely on it, and I think I didnβt think when I implemented it ...
Anyway,. If I get the reader this way, I have no way to close the connection, and if I close the connection before the reader calls the read () method, it will explode when it goes on reading and says that the database connection is necessary for opening.
The question is, how can I close the connection with the previous code bodies? Or all connections are generally possible ..
From what I read here , unless you specifically name 'close ()', it does not close, and if you use file access in 2003, it leaves you in a world of pain.
source share