How to find an unclosed DataReader?

I support a large application in ASP.Net 1.1 that has been modified by many people (including students). Obviously, the code was rarely viewed, so there are many ... errors ... stupid errors. The most problematic are the never-closed DataReader. And there is everywhere, up to ten per page. Since this project is about a hundred pages with ease over 300 classes, I just got depressed at the thought of finding all the unclosed DataReader.

I know this is hopeless, but is there an easy way to find all these unclosed DataReaders? some software or visual studio 2003 tweak ...

+3
source share
2 answers

Well, the “right” way to use DataReader is

using (SqlDataReader dr = ...) {
    ...
}

or

SqlDataReader dr = ...
try {
    ...
} finally {
    dr.Close();
}

, , SqlDataReader IDataReader.

  • try

.

, :

SqlDataReader dr = ...
...
// do something
...
dr.Close();

, , // do something, DataReader.

+3

" ". .

  • {SqlDataReader.*}$ using(\1) \{.
  • using({using(.*)} \{ \1.
  • .

, .

, , using, .

+1

All Articles