1

I am trying to get the data from the Sybase database. But when I try to dispose or close the connection it throws the exception SQL Runtime Error ...???. No inner exception, no other details. Here is the code I am trying

try
{
    List<Dataclass> lstDataclass = new List<Dataclass>();
    using (IDataReader reader = this.ExecuteReader(CommandType.StoredProcedure, Constants.ProcedureName, lstSQLParameter))
    {
        if (reader != null)
        {
           while (reader.Read())
           {
              lstDataclass.Add(ReadData(reader) as Dataclass);
           }
        }
    }//Here is exception is thrown
    return lstDataclass ;
}
catch (Exception ex)
{
      Logging.CDSLogger.LogEntry(MethodBase.GetCurrentMethod(), ex.Message, TraceEventType.Error);
      throw;
}

This code throws the exception as mentioned above the stacktrace for this is as,

at iAnywhere.Data.SQLAnywhere.SAInternalConnection.CheckException(Int32 idEx, Boolean freeConn)
at iAnywhere.Data.SQLAnywhere.SAInternalConnection.ReturnToPool()
at iAnywhere.Data.SQLAnywhere.SAConnectionPool.ReturnConnection(SAInternalConnection connection)
at iAnywhere.Data.SQLAnywhere.SAConnectionPoolManager.ReturnConnection(SAInternalConnection connection)
at iAnywhere.Data.SQLAnywhere.SAConnection.Dispose(Boolean disposing)
at iAnywhere.Data.SQLAnywhere.SAConnection.Close()
at iAnywhere.Data.SQLAnywhere.SADataReader.myDispose(Boolean disposing)
at iAnywhere.Data.SQLAnywhere.SADataReader.myDispose()
at iAnywhere.Data.SQLAnywhere.SADataReader.Close()
at BusinessLayer.BusinessCheckRegisterTable.GetAllDataForNacha(EntityEDIScreenRemittanceExport entityScreenRE) in 

And if I remove the using then it runs fine. Even If I try to to Close() the connection the same exception is thrown.This only happens for sybase not any other database.

Any help would be great. If anything confusing or not understandable please feel free to comment.

Mahesh
  • 8,694
  • 2
  • 32
  • 53
  • That looks like a possible bug in the framework you are using =/ Dispose should *never* throw an exception. – Travis J Sep 08 '15 at 20:50
  • 1
    I think it may be the problem with the sybase driver. – Rahul Sep 08 '15 at 20:51
  • Is there a reason why you are using IDataReader instead of DataReader? Also when you are using "using", you do not need to dispose of the object, it will automatically be closed after "using" finished executing – Coding Duchess Sep 08 '15 at 20:51
  • @TravisJ Excatly my toughts – Mahesh Sep 08 '15 at 20:54
  • @Rahul Excatly my thoughts – Mahesh Sep 08 '15 at 20:54
  • 1
    Yeah, it's a bug with sybase ASE driver. See here http://stackoverflow.com/questions/1913779/sybase-internal-error-30016. Go ahead and Stone them. – Rahul Sep 08 '15 at 20:54
  • @ElenaDBA I amnot calling the `Dispose()` manually. `IDataReader` calls it. And then the Problem happens – Mahesh Sep 08 '15 at 20:55
  • 1
    You don't show how this.ExecuteReader instantiates the data reader but I expect that a command and a connection are involved. One suspicion: Maybe this particular implementation of a data reader closes the connection immediately after all Read calls have been made by your application. And then the ReturnConnection logic might throw an exception because it receives a closed connection, but the exception should obviously not leak out Dispose. Take a look at the various CommandBehavior, you can use those to influence whether a reader's connection gets automatically closed or not. – Christoph Sep 08 '15 at 20:56
  • @Christoph It's not the closed connection issue. Because that throws different exception all together. And I already checked over the code if thats the case. Still thanks for the help. – Mahesh Sep 08 '15 at 21:00

0 Answers0