Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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();
}
like image 405
vocero Avatar asked Nov 07 '11 18:11

vocero


People also ask

Can multiple-step OLE DB operations generate errors?

Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. windows-wpf

What are the different scenarios in which ADO errors 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

What is the difference between ADO and MSDASQL?

I've written many apps designed to work on both SQL and Access using ADO, the only difference should be (other than changing a few select statements, Access doesn't support the same joins as T-SQL) the provider and connection string. The MSDASQL provider is older and uses ODBC as an intermediary layer.

What are the different types of access error scenarios?

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


7 Answers

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.

like image 160
EdsonF Avatar answered Sep 28 '22 13:09

EdsonF


It is type mismatch, try

rs.Fields["id"].Value = "0";

or make sure you assign a Variant to the value.

like image 34
Olix Avatar answered Sep 28 '22 13:09

Olix


Since I posted this problem, we figured out that the problem was when you do a union the attributes on the fields are not bound (i.e. the attributes: basecatalog, basetable & basecolumn are empty) to remedy our problem we had to force the values of those attributes, by saving the recordset to xml (adPersistXML), change the xml and reopen the recordset from the xml. This rebound the fields and we were able to continue. We know this may not be the most efficient solution, but it was for an older app and we didn't want to rewrite the sql statements. It looks like the main error Multiple-step operation generated errors. Check each status value. is related to when an error occurs when a value is assigned to a field.

like image 43
vocero Avatar answered Sep 28 '22 13:09

vocero


Two things I can think of... Make sure your "ID" column will accept a zero (0). Also - I've stopped this issue on one occasion by not using the adUseClient cursor (try server).

Many times this is a type mismatch, trying to stuff a NULL into a non-null column, or attempting to write more characters into a column than it's designed to take.

Hope this helps. - Freddo

like image 28
Freddo Avatar answered Sep 28 '22 11:09

Freddo


I found another scenario:

When I was trying to set the value of a adLongVarChar field in a new record for a memory-only adodb.recordset. In my case, the error was triggered because the string I was passing had a buried unicode character.

like image 37
J Cloud Avatar answered Sep 28 '22 13:09

J Cloud


Same issue occurred to me the problem was that i violated an object property , in my case it was size the error came out as

"IntegrationException: Problem (Multiple-step operation generated errors. Check each status value.)"

  Imports ADODB
  Dim _RecordSet As Recordset  
  _rs.Fields.Append("Field_Name", DataTypeEnum.adVarChar, 50)

  _Recordset("Field_Name").Value = _RecordDetails.Field_NameValue

_RecordDetails.Field_NameValue length was more than 50 chars , so this property was violated , hence the error occurred .

like image 44
Wesam Avatar answered Sep 28 '22 11:09

Wesam


I found this error when our legacy application was trying to parse 1/1/0001 12AM date and time. Looks like VB6 recordsets doesn't like that value. To get rid of the errors, I had to set all the offending dates to null.

like image 28
Dithos Avatar answered Sep 28 '22 13:09

Dithos