1

I have legacy code with the logic as seen here:

using (SqlDataReader drColor = ColorDal.GetColors())
{
   if (drColor.HasRows)
   {
      string colorCacheKey = string.Empty;
      //_log.Debug("Total Color Count loaded from database: " + dsColor.Tables.Count.ToString());

      // Retrieve each colorfamily present in the dataset.
      while (drColor.Read())
      {
         ......
      }
   }

   drColor.Close(); // This is line # in the exception.
}

Intermittently I am getting the following exception in my ASP.NET MVC app:

[InvalidOperationException: Internal connection fatal error.]
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +6355814
System.Data.SqlClient.SqlDataReader.CloseInternal(Boolean closeReader) +308
System.Data.SqlClient.SqlDataReader.Close() +293

Could closing the SqlDataReader inside using{} be the cause of it?

Thanks.

3
  • 2
    When the using block exits, it should call close and dispose, so while that is likely not the culprit, the code is unnecesary anyways.
    – Tejs
    Apr 27, 2012 at 18:04
  • 1
    Tejs is right - 'using' is the right way to go. The .Close() isn't needed, but that's not causing your problem. I suspect something is happening to the conneection during the read - perhaps another thread closing it?
    – n8wrl
    Apr 27, 2012 at 18:07
  • I know that when exiting using block, it closes and disposes of the connections, but the stack trace mentions the line # in which the datareader is being closed, hence I am getting a bit confused reg the reason for the error.
    – parsh
    Apr 27, 2012 at 18:09

1 Answer 1

-1

This may help...not sure where they're at with this bug, but it might give you a place to start:

http://connect.microsoft.com/VisualStudio/feedback/details/772492/internal-connection-fatal-error-system-invalidoperationexception

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.