lunes, 25 de junio de 2012

Invalid Descriptor Index

Error:
[Microsoft][SQL Server Native Client 10.0]Invalid Descriptor Index
I've seen this error twice now in Ax 2009, and it's time to tell the world about it.  We have an external SQL Server database to import and register new invoices.  Example:
SELECT InvoiceSeriesNum, Note, ServiceDate, ExchRateSales FROM SomeTable WHERE Transferred=0
Using the OdbcConnection/Statement/ResultSet/LoginProperty classes we can import the data.  Code snippet:
    _intCustInvoiceTable.AssetId            = _resultSet.getString(#IntCustInvoice_AssetId);
    _intCustInvoiceTable.InvoiceSeriesNum   = _resultSet.getString(#IntCustInvoice_SeriesNum);
    _intCustInvoiceTable.Note               = _resultSet.getString(#IntCustInvoice_Note);
    _intCustInvoiceTable.ServiceDate        = _resultSet.getDate(#IntCustInvoice_ServiceDate);
    _intCustInvoiceTable.ExchRateSales      = _resultSet.getReal(#IntCustInvoice_ExchRateVend);
It happens that we now have a new field to add to the query. Thus:
SELECT InvoiceSeriesNum, Note, ServiceDate, ExchRateSales, AnotherField FROM SomeTable WHERE Transferred=0
    _intCustInvoiceTable.AssetId            = _resultSet.getString(#IntCustInvoice_AssetId);
    _intCustInvoiceTable.InvoiceSeriesNum   = _resultSet.getString(#IntCustInvoice_SeriesNum);
    _intCustInvoiceTable.Note               = _resultSet.getString(#IntCustInvoice_Note);
    _intCustInvoiceTable.ServiceDate        = _resultSet.getDate(#IntCustInvoice_ServiceDate);
    _intCustInvoiceTable.AnotherField       = _resultSet.getReal(#IntCustInvoice_AnotherField);
    _intCustInvoiceTable.ExchRateSales      = _resultSet.getReal(#IntCustInvoice_ExchRateVend);
You'll notice, unlike me for the past two hours, that we've added the AnotherField out of order while reading it in from the ResultSet.  By moving it down to the same index as the modified query it should work.  The problem is most likely caused by reading columns out of order.  To resolve the error in the example above, simply move our new field highlighted in red down a line, or edit the original query to change the columns around.

No hay comentarios:

Publicar un comentario