C
Chris Gallucci
I have a program that creates an instance of a SqlDataReader via the
Microsoft Application Blocks Data Access code.
I use a typical try{} catch{} finally{} pattern for using it...
<codesnippet>
SqlDataReader rdr = SqlManager.ExecuteReader(/* yada, yada, yada */);
try {
while ( rdr.Read() ) {
if ( _stop == true ) break;
// do work
}
}
catch ( Exception ex ) {
// handle error
}
finally {
if ( rdr != null && !rdr.IsClosed ) {
rdr.Close();
}
}
// other stuff to do
</codesnippet>
My problem is that when I exit my "while ( rdr.Read() )" loop before I've
finished reading the rest of the resultset, the call to close behaves
strangely.
Strangely is defined as causing the application to immediately exit. There
is no error thrown, no log written to the event log or to disk (that I can
find). Even in a debug environment there is nothing written to the output
window such as you would expect for a properly terminating and unloading
application.
Can anybody help or shed some light on this problem for me? Maybe something
I can do to better isolate the problem?
Thanks,
ChrisG
Microsoft Application Blocks Data Access code.
I use a typical try{} catch{} finally{} pattern for using it...
<codesnippet>
SqlDataReader rdr = SqlManager.ExecuteReader(/* yada, yada, yada */);
try {
while ( rdr.Read() ) {
if ( _stop == true ) break;
// do work
}
}
catch ( Exception ex ) {
// handle error
}
finally {
if ( rdr != null && !rdr.IsClosed ) {
rdr.Close();
}
}
// other stuff to do
</codesnippet>
My problem is that when I exit my "while ( rdr.Read() )" loop before I've
finished reading the rest of the resultset, the call to close behaves
strangely.
Strangely is defined as causing the application to immediately exit. There
is no error thrown, no log written to the event log or to disk (that I can
find). Even in a debug environment there is nothing written to the output
window such as you would expect for a properly terminating and unloading
application.
Can anybody help or shed some light on this problem for me? Maybe something
I can do to better isolate the problem?
Thanks,
ChrisG