0

I'm trying to open an access database with the extension .accdb so I can read some information from this database. I have no problem doing this, if I use the wizard:

enter image description here

enter image description here

enter image description here

enter image description here

However when try to use code to do this I always get an exception when I try to connect: enter image description here

enter image description here

From debugging I understood that the exception comes from not having opened the connection. So I open the connection but the the database comes as empty:

enter image description here

I have looked around stack overflow and tried to apply many of the answers to similar questions but they haven't worked. In theory if I can connect through the wizard I should also be able to connect through OleDBConnection object in C#. How can I fix this?

8
  • I'm not sure but how about using Provider = Microsoft.Jet.OLEDB.4.0;? Commented Sep 7, 2016 at 14:42
  • have you tried to do a simple sql request to it? using OleDbDataReader? Commented Sep 7, 2016 at 14:42
  • Please post the code where you instantiate the DataAdapter and set its query string. Commented Sep 7, 2016 at 14:42
  • 1
    That doesn't work for the new extension of access databases .accdb. You have to use 12.0. Commented Sep 7, 2016 at 14:43
  • @JohnWu I have updated my question. Commented Sep 7, 2016 at 14:46

1 Answer 1

1

I found the problem. My table name had a space between "Tab_Project Data" and because I didn't use [] it was looking for a table named "Tab_Project" which it couldn't find. So I just had to put "[Tab_Project Data]" inside my query and now it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.