Microsoft Access OledbDataReader read values error

时间:2015-06-26 10:24:18

标签: c# ms-access oledb jet

I am connecting to MS Access file with jet Engine x64,but also worked x86 platform. I am getting error while trying to read data

            long sizeCounter = 0, rowIndex = 0;
            var secondValues = new object[BatchSize][];

            for (var secondIndex = 0; secondIndex < secondValues.Length; secondIndex++)
                secondValues[secondIndex] = new object[reader.FieldCount];

            while (reader.Read())
            {
               //TODO:Error get from here...
                reader.GetValues(secondValues[sizeCounter]);

                sizeCounter++;

                if (NotifyAfter > 0 && (rowIndex % NotifyAfter == 0 && rowIndex > 0 && RowsCopied != null))
                {
                    RowsCopied(this, new RowsCopiedEventArgs(rowIndex));
                }

                if (sizeCounter == BatchSize)
                {
                    RunBulkCopy(secondValues);

                    sizeCounter = 0;
                }

                rowIndex++;
            }

            var lastValues = new object[sizeCounter][];

            for (var lastIndex = 0; lastIndex < sizeCounter; lastIndex++)
                lastValues[lastIndex] = secondValues[lastIndex];

            RunBulkCopy(lastValues);

            if (RowsCopied != null)
                RowsCopied(this, new RowsCopiedEventArgs(rowIndex));
        }
        catch (Exception)
        {
            if (RowsCopied != null)
                RowsCopied(this, new RowsCopiedEventArgs
                {
                    Abort = true
                });
        } 

Unable to cast COM object of type 'System.__ComObject' to interface type 'IRowset'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{0C733A7C-2A1C-11CE-ADE5-00AA0044773D}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Thanks!

1 个答案:

答案 0 :(得分:0)

OleDb数据连接器在多线程项目中使用时有一个错误。在STA公寓中创建OleDb对象并从MTA调用它时会抛出异常。

Microsoft report of the issue