I run a standard query against a DB2 database with C# ADO.NET OleDb and using statements and get System.Data.OleDb.OleDbException (0x80004005): CLI0115E Invalid cursor state. SQLSTATE=24000 When I include the dispose methods for each OleDb object, the query runs. Why does this fail without the Dispose methods? From everything i have researched the using statements should dispose of the objects for me. I am using .NET 4.5.1
using (OleDbConnection conn = DBConn.BIPSConn)
{
using (OleDbCommand cmd = new OleDbCommand(query, conn))
{
using (OleDbDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
string orderNumber = rdr.GetString(0).Trim();
string originCode = rdr.GetString(1).Trim();
string destinationCode = rdr.GetString(3).Trim();
Record record = new Record(orderNumber, originCode, destinationCode);
RecordList.Add(record);
}
// for unknown reasons, without these dispose methods we get an Invalid Cursor State error
rdr.Dispose();
}
cmd.Dispose();
}
conn.Dispose();
}
You have a using block -- you don't want to call Dispose() you want to call Close(). The using block will take care of the dispose. Add in a call to Close instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.