0

Possible Duplicate:
IErrorInfo.GetDescription failed with E_FAIL(0x80004005).System.Data while data adapter Fill()

Below is the code I have to connect to an Access database in C#. The connection appears to open just fine (no exception is thrown by the conn.Open() command), however when it gets to the cmd.ExecuteReader() I get the following error message:

"IErrorInfo.GetDescription failed with E_Fail(0x80004005)."

I have checked and double checked to make sure the spelling is correct on the table I'm trying to pull from as well.

        System.Data.OleDb.OleDbConnection conn = new
        System.Data.OleDb.OleDbConnection();
        conn.ConnectionString = @"Provider=Microsoft Office 12.0 Access Database Engine OLE DB Provider;" +
                                @"Data source= C:\Users\nearod\Desktop\ImportDB.accdb";
        try
        {
            conn.Open();
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM SQL ID Test Load", conn);

            OleDbDataReader reader = cmd.ExecuteReader();


            // Insert code to process data.
        }
        catch (Exception ex)
        {
            MessageBox.Show("Failed to connect to data source");
        }
        finally
        {
            conn.Close();
        }
4

1 回答 1

1

Try changing

OleDbCommand cmd = new OleDbCommand("SELECT * FROM SQL ID Test Load", conn);

To

OleDbCommand cmd = new OleDbCommand("SELECT * FROM [SQL ID Test Load]", conn);
于 2012-08-22T18:56:18.160 回答