Getting "Multiple-step operation generated errors. Check each status value." error using ADO with SQL server 2008

vocero picture vocero · Nov 7, 2011 · Viewed 65.7k times · Source

We are in the process to migrate our SQL 2000 box to SQL 2008. But we ran into an issue; when a result set (rows or not) is returned by using a query that has a UNION. Later in the code we try to add a new row and assign field to it but because a UNION was used, when we try to assign a value to the field it gives us a Multiple-step operation generated errors. Check each status value. error. We tried the following code on a Windows XP & Windows 7 and got the same result. But when we change our connection string to point back to our SQL 2000 box we don't get that error any more.

The following example show the problem we are having.

var c = new ADODB.Connection();
var cmd = new ADODB.Command();
var rs = new ADODB.Recordset();
object recordsAffected;

c.Open("Provider=SQLOLEDB;Server=*****;Database=*****;User Id=*****;Password=*****;");

cmd.ActiveConnection = c;
cmd.CommandType = ADODB.CommandTypeEnum.adCmdText;
cmd.CommandText = "create table testing2008 (id int)";
cmd.Execute(out recordsAffected);

try {
    cmd.CommandText = "select * from testing2008 union select * from testing2008";

    rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
    rs.Open(cmd, Type.Missing, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockBatchOptimistic, -1);

    rs.AddNew();
    rs.Fields["id"].Value = 0; //throws exception
    rs.Save();
}
catch (Exception ex) {
    MessageBox.Show(ex.ToString());
}
finally {
    cmd.CommandText = "drop table testing2008";
    cmd.Execute(out recordsAffected);
    c.Close();
}

Answer

EdsonF picture EdsonF · May 1, 2014

The link below is an article that gives a great breakdown of the 6 scenarios this error message can occur:

Scenario 1 - Error occurs when trying to insert data into a database

Scenario 2 - Error occurs when trying to open an ADO connection

Scenario 3 - Error occurs inserting data into Access, where a fieldname has a space

Scenario 4 - Error occurs inserting data into Access, when using adLockBatchOptimistic

Scenario 5 - Error occurs inserting data into Access, when using Jet.OLEDB.3.51 or ODBC driver (not Jet.OLEDB.4.0)

Scenario 6 - Error occurs when using a Command object and Parameters

http://www.adopenstatic.com/faq/80040e21.asp

Hope it may help others that may be facing the same issue.