Strange error when filling a data adapter.

Posted by Tim C on Stack Overflow See other posts from Stack Overflow or by Tim C
Published on 2010-03-26T01:31:51Z Indexed on 2010/03/26 2:03 UTC
Read the original article Hit count: 401

Filed under:
|
|
|

I am receiving the following error in my code (c#, .Net 3.5, VS2008) when I try to connect to an Excel sheet and fill a OleDbDataAdapter with the results of a query. First the error:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

And here is the code, which is honestly pretty simple:

var excelFileName = string.Format("c:/Metadata_Tool.xlsm");
var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0}; Extended Properties=Excel 12.0;HDR=YES;", excelFileName);

var adapter = new OleDbDataAdapter("Select * FROM [Video Tagging XML]", connectionString);
var ds = new DataSet();

adapter.Fill(ds, "VTX");

DataTable data = ds.Tables["VTX"];

foreach (DataRow myRow in data.Rows)
{
    foreach (DataColumn myColumn in data.Columns)
    {
        Console.Write("\t{0}", myRow[myColumn]);
    }
    Console.WriteLine();
}

Console.ReadLine();

I get the error on the line adapter.Fill(ds,"VTX");. I did find a microsoft forum post saying to turn on JIT optimization in VS2008 from the Tools/Options/Debug/General menu, but this did not seem to help. Any help would be greatly appreciated thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET