0

I am getting an

IErrorInfo.GetDescription failed with E_FAIL(0x80004005)

And I don't know what this means nor how to solve it. When I copy and paste the exact query into my Access-db and run it it works like a charm but when I try and run it in c# I get this error.

The parameters all do get filled with the right values.

@aankomst = 15-11-2017, @vertrek = 20-11-2017, @grootte = "large"

    try
    {
        standplaatslijst.Clear();
        verbinding = new OleDbConnection(
        @"Provider=Microsoft.ACE.OLEDB.12.0;
        Data Source=..\..\..\La_Rustique.accdb;
        Persist Security Info=False;");
        verbinding.Open();

        OleDbCommand query = new OleDbCommand();
        OleDbDataReader lezer = null;
        query.CommandText = @"SELECT *
                              FROM standplaats
                              WHERE id not in (SELECT standplaats_id
                              FROM reservering
                               WHERE @aankomst BETWEEN aankomst AND vertrek
                               AND @vertrek BETWEEN aankomst AND vertrek)
                               AND size = @grootte";

        query.Connection = verbinding;

        query.Parameters.Add(new OleDbParameter("@aankomst", OleDbType.DBDate));
        query.Parameters["@aankomst"].Value = aankomst;
        query.Parameters.Add(new OleDbParameter("@vertrek", OleDbType.DBDate));
        query.Parameters["@vertrek"].Value = vertrek;
        query.Parameters.Add(new OleDbParameter("@grootte", OleDbType.VarChar));
        query.Parameters["@grootte"].Value = grootte;

        lezer = query.ExecuteReader();

        while (lezer.Read())
        {
            standplaatslijst.Add(new standplaats(lezer));
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        verbinding.Close();
    }

I'm adding the reader to a new class called standplaats which looks like this:

public standplaats(OleDbDataReader lezer)
    {
        _id = lezer.GetInt32(0);
        Grootte = lezer.GetString(1);
        Name = lezer.GetString(2);
    }
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Jelle Taal
  • 25
  • 1
  • 7
  • At the beginning is `SQL.standplaatslijst.Clear();`. Later is `standplaatslijst.Add(new standplaats(lezer));`. First one starts with `SQL`; second one doesn't. That looks odd. Not sure what that means; can you translate? I get 'rank list' but maybe there's better word. – wazz Nov 15 '17 at 09:33
  • @wazz standplaatsenlijst is a list in the class sql and sql is the class I'm working in currently. ill remove the SQL. part to make it clearer. thanks for your feedback – Jelle Taal Nov 15 '17 at 09:39
  • I think the problem is in `standplaatslijst.Add(new standplaats(lezer));`. You want a new List item but you're providing the entire Reader, instead of data from the Reader. – wazz Nov 15 '17 at 09:48
  • 1
    Just a thought. Watch out for reserved words. Maybe try wrapping come fields in [ ]. ex: `WHERE [id] not in... Probably not an issue... – wazz Nov 15 '17 at 10:03
  • 1
    I've seen this fix a few times now: https://stackoverflow.com/questions/15534284/what-is-causing-my-oledbexception-ierrorinfo-getdescription-failed-with-e-fail – wazz Nov 15 '17 at 10:13

1 Answers1

1

SIZE is a reserved word in MS Access.

Change the query to this:

query.CommandText = @"SELECT *
                      FROM standplaats
                      WHERE id not in (SELECT standplaats_id
                      FROM reservering
                       WHERE @aankomst BETWEEN aankomst AND vertrek
                       AND @vertrek BETWEEN aankomst AND vertrek)
                       AND [size] = @grootte";

Here you find the list of reserved words.

MatSnow
  • 7,357
  • 3
  • 19
  • 31