2017-06-22 36 views
-1

我们在运行DB2ResultSet.Read()的应用程序时遇到问题。有时会得到错误:DB2ResultSet.Read()。错误[24000] [IBM] CLI0115E光标状态无效。 SQLSTATE = 24000

[24000] [IBM] CLI0115E光标状态无效。 SQLSTATE = 24000。

数据库:DB2为Linux,UNIX和Windows V10.5 客户端:64位Windows 7

方法:

public int EventGetEvSegmentCnt(string SegmentID, string strEvntGroup) 
      { 
       int strGroupCnt = 0; 
       string strSQL = string.Empty;`enter code here` 
       DB2ResultSet objRs; 
       if (string.IsNullOrEmpty(SegmentID) || string.IsNullOrEmpty(strEvntGroup)) 
       { 
        strGroupCnt = 0; 
       } 
       else 
       { 
        strSQL = " SELECT COUNT(EVNT_CODE) AS EVNT_GROUP_COUNT FROM E_SEGMENT_EVENT WHERE C_SEGMENT_ID = " + SegmentID + " AND EVNT_GROUP = " + strEvntGroup; 
        Common.DatabaseHelper helper = new Common.DatabaseHelper(); 
        objRs = helper.ExecuteResultSet(strSQL); 
        if (objRs.Read()) 
        { 
         strGroupCnt = 0; 
        } 
        else 
        { 
         strGroupCnt = int.Parse(objRs["EVNT_GROUP_COUNT"].ToString()); 
        } 
       } 
       return strGroupCnt; 

      } 

错误消息:

[Information] System.Web.HttpUnhandledException (0x80004005): 

    Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> IBM.Data.DB2.DB2Exception (0x80004005): ERROR [24000] [IBM] CLI0115E Invalid cursor state. SQLSTATE=24000 
     at IBM.Data.DB2.DB2DataBuffer.FetchScroll(FetchType fetchType, Int64 offset, Int32 numRows) 
     at IBM.Data.DB2.DB2DataBuffer.FetchNext() 
     at IBM.Data.DB2.DB2DataReader.Fetch(FetchDirection direction, Int64 offset, Boolean& isDeleted) 
     at IBM.Data.DB2.DB2ResultSet.Read() 

请帮助。

DatabaseHelper:

public class DatabaseHelper 
    { 
     public DatabaseHelper() 
     { 
     } 

     public DataSet ExecuteDataSet(string commandText, List<DB2Parameter> parameters = null) 
     { 
      var command = GetCommand(commandText, parameters); 
      var adapter = new DB2DataAdapter(); 

      adapter.SelectCommand = command; 

      var ds = new DataSet(); 
      adapter.Fill(ds); 


      adapter.Dispose(); 

      return ds; 
     } 

     public DB2DataReader ExecuteReader(string commandText, List<DB2Parameter> parameters = null) 
     { 
      var command = GetCommand(commandText, parameters); 
      return command.ExecuteReader(CommandBehavior.CloseConnection); 
     } 

     public DB2ResultSet ExecuteResultSet(string commandText, List<DB2Parameter> parameters = null) 
     { 
      var command = GetCommand(commandText, parameters); 
      //DB2ResultSet result = command.ExecuteResultSet(CommandBehavior.Default, DB2CursorType.Dynamic); 
      DB2ResultSet result = command.ExecuteResultSet(CommandBehavior.CloseConnection, DB2CursorType.Dynamic); 
      return result; 
     } 

     public DB2ResultSet ExecuteResultSetStatic(string commandText, List<DB2Parameter> parameters = null) 
     { 
      var command = GetCommand(commandText, parameters); 
      // DB2ResultSet result = command.ExecuteResultSet(CommandBehavior.Default, DB2CursorType.Static); 
      DB2ResultSet result = command.ExecuteResultSet(CommandBehavior.CloseConnection, DB2CursorType.Static); 
      return result; 
     } 

     public int ExecuteNonQuery(string commandText, List<DB2Parameter> parameters = null) 
     { 
      var command = GetCommand(commandText, parameters); 
      int result = command.ExecuteNonQuery(); 
      command.Connection.Close(); 
      return result; 
     } 

     public void ExecuteSQLArray(string[] arrSQL) 
     { 
      var command = new DB2Command(); 
      command.Connection = GetConnection(); 
      command.CommandType = CommandType.Text; 
      command.CommandTimeout = 600; 
      command.Transaction = command.Connection.BeginTransaction(); 
      try 
      { 
       foreach (string strSQL in arrSQL) 
       { 
        if (!string.IsNullOrEmpty(strSQL)) 
        { 
         command.CommandText = strSQL; 
         command.ExecuteNonQuery(); 
        } 
       } 
       command.Transaction.Commit(); 
      } 
      catch (Exception) 
      { 
       command.Transaction.Rollback(); 
       throw; 
      } 
      command.Connection.Close(); 
      command.Dispose(); 
     } 

     public DB2Connection GetConnection() 
     { 
      var conn = new DB2Connection(System.Configuration.ConfigurationManager.ConnectionStrings["DB2_Conn"].ConnectionString); 
      conn.Open(); 
      return conn; 
     } 

     public DB2Command GetCommand(string commandText, List<DB2Parameter> parameters) 
     { 
      var command = new DB2Command(commandText); 
      command.Connection = GetConnection(); 
      command.CommandTimeout = 600; 

      if (parameters != null) 
      { 
       foreach (var parameter in parameters) 
       { 
        command.Parameters.Add(parameter); 
       } 
      } 

      return command; 
     } 
    } 
+0

我相信在某处'helper.ExecuteResultSet'你关闭游标。 – mustaccio

+0

我只调用DB2Command的ExecuteResultSet函数。 – jason

回答

0

试试这个:

public int EventGetEvSegmentCnt(string SegmentID, string strEvntGroup) 
    { 
     if (string.IsNullOrEmpty(SegmentID) || string.IsNullOrEmpty(strEvntGroup)) return 0; 

     int strGroupCnt = 0; 

     DataSet objDS=null; 

     string strSQL = string.Format(" SELECT COUNT(EVNT_CODE) AS EVNT_GROUP_COUNT FROM E_SEGMENT_EVENT WHERE C_SEGMENT_ID ={0} AND EVNT_GROUP = {0}", SegmentID, strEvntGroup); 

     try 
     { 
      Common.DatabaseHelper helper = new Common.DatabaseHelper(); 
      objDS = helper.ExecuteDataSet(strSQL); 
      if (objRs.Table[0].Rows.Count > 0) 
      { 
       strGroupCnt = int.Parse(objDS.Tables[0].Rows[0]["EVNT_GROUP_COUNT"].ToString()); 
      } 
     } 
     finally 
     { 
      if (objDS != null) objDS.Dispose() 

      return strGroupCnt; 
     } 
    } 
相关问题