Visual Studio Fatal Error 0x80131c39

1

Im working on a project that will read a excel document and return a dataset. The error only happens when trying to execute this code.

I dont understand what is wrong with this code ive have tried using multiple excel files.

public static DataSet ImportExcelXLS(string FileName, bool hasHeaders) {
string HDR = hasHeaders ? "Yes" : "No";
string strConn;
if (FileName.Substring(FileName.LastIndexOf('.')).ToLower() == ".xlsx")
    strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName + ";Extended Properties=\"Excel 12.0;HDR=" + HDR + ";IMEX=0\"";
else
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileName + ";Extended Properties=\"Excel 8.0;HDR=" + HDR + ";IMEX=0\"";

DataSet output = new DataSet();

using (OleDbConnection conn = new OleDbConnection(strConn)) {
    conn.Open();

    DataTable schemaTable = conn.GetOleDbSchemaTable(
        OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });

    foreach (DataRow schemaRow in schemaTable.Rows) {
        string sheet = schemaRow["TABLE_NAME"].ToString();

        if (!sheet.EndsWith("_")) {
            try {
                OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + sheet + "]", conn);
                cmd.CommandType = CommandType.Text;

                DataTable outputTable = new DataTable(sheet);
                output.Tables.Add(outputTable);
                new OleDbDataAdapter(cmd).Fill(outputTable);
            } catch (Exception ex) {
                throw new Exception(ex.Message + string.Format("Sheet:{0}.File:F{1}", sheet, FileName), ex);
            }
        }
    }
}
return output;
} 
c#
excel
visual-studio-2012
dataset
asked on Stack Overflow Jun 25, 2015 by nickivey

1 Answer

1

Looking for that specific error yielded info that it means CORDBG_E_MISMATCHED_CORWKS_AND_DACWKS_DLLS

Further research on another SO thread with same error code reveals that this means that there is a fatal mismatch between the CLR version and the debugger version. That is as bad as it sounds.

Supposedly someone solved before by reverting to .net 3.5 usage...It does not seem to be your code specifically. More a problem with dll versions.

references:

answered on Stack Overflow Jun 25, 2015 by tendrel • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0