|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ExecuteReader returns closed DataReaderUsing .net 2 and Sql Server 2005, I am intermittently getting the exception:
Invalid attempt to FieldCount when reader is closed. What I don't understand is how the DataReader could be closed when it was just created by ExecuteReader. As in: dr = cmd.ExecuteReader() ; Console.Write ( dr.FieldCount ) ; If there's a problem (like the connection is closed) then why doesn't ExecuteReader throw an exception? (For that matter, why doesn't ExecuteScalar?) Even though I haven't tried to confirm this, I am guessing you have to at
least advance to the first row in the result set before trying to look at the field count,etc. Show quote "PIEBALD" <PIEB***@discussions.microsoft.com> wrote in message news:942AB81E-4D97-4597-BB8B-5DC95EA0B731@microsoft.com... > Using .net 2 and Sql Server 2005, I am intermittently getting the > exception: > > Invalid attempt to FieldCount when reader is closed. > > What I don't understand is how the DataReader could be closed when it was > just created by ExecuteReader. > > As in: > > dr = cmd.ExecuteReader() ; > Console.Write ( dr.FieldCount ) ; > > If there's a problem (like the connection is closed) then why doesn't > ExecuteReader throw an exception? (For that matter, why doesn't > ExecuteScalar?) |
|||||||||||||||||||||||