Link to home
Start Free TrialLog in
Avatar of cctest
cctest

asked on

Open Access 2007 (.accdb) in VS.NET 2005

I'm working with C# 2005. Currently I have a project utilizing an Access database, and my company has recently upgraded everything to Access 2007. I tried to open the new Access database (.accdb) but failed to do that. I received the message "unrecognized database format." Anyone please help me.
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Hi cctest ....

Well, just for good measure, did you do a Compact and Repair on the ACCDB file ?

Also, from with inside you C# program, you may need to change you connection string ... using ACCDB instead of MDB?  I have done a couple of small C# pgrms wherein I connected to an Access mdb.  If these suggestions don't do it, could you post the relevant code?

mx
Can you post the connection string you're using?
ASKER CERTIFIED SOLUTION
Avatar of fredvr666
fredvr666

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Other than the typo (should be Data Source=C:\db1.accdb - too many backslashes) this should work.

Are you sure that your database is in the new format? 2007 can still open and use the .mdb format as well ...
Avatar of fredvr666
fredvr666

It's not a typo C# needs the second backslashe in a string

I made a new access 2007 database called db1.accdb
and I test the code for you it workes fine
except when you run the code from a network drive,then you got an exception

<It's not a typo C# needs the second backslashe in a string>

Okay ... learn something new every day!!

Are you sure you're connected to the drive?

Does your Windows username have the necessary permissions on that folder? In order to open and use the db, you'll need Read/Write/Create/Destroy permissions on that folder.

Do you get any error message with the exception?
<Does your Windows username have the necessary permissions on that folder? In order to open and use the db, you'll need Read/Write/Create/Destroy permissions on that folder.>

No that's not the problem, .net framework checks if the application is trusted, if not it throws an exception such as: Request for the permission of type 'System.Data.OleDb.OleDvPermission...."

You can add a trusted app in control panel administrative tools | Microsoft .NET Framework 2.0 Configuration, BUT with the new distribution and Vista you need the sdk.
Executing the app from a local path everything's ok.

coming back to the backslash, it is interpret like an escape character so use a double \ OR
you can add an @ like:
string Sql = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\db1.accdbPersist Security Info=False;";
I've not worked in C# much, but I can tell you this: If you don't have the necessary permissions on the folder, then Jet (not the .NET framework) will not be able to properly create the lockfile, and you may not be able to open the file.

Of course, you can check this pretty easily by navigating to the network resource and attempting to open the file directly (assuming you have Access installed on your machine, that is). If you can open the file, then check the directory to see if a lockfile (ending in .ldb) is created in that directory.
it's not the database file, if you read the example it's on C:\.
It's the application!
<I made a new access 2007 database called db1.accdb
and I test the code for you it workes fine
except when you run the code from a network drive,then you got an exception>

<it's not the database file, if you read the example it's on C:\.>

so you code is executing on the server and the database file is on C:\ of the same server?

Does the server have the correct driver for accdb?
stevbe your rank is genius, can you read?
A better question would be: Can YOU read. From your own posting:

<except when you run the code from a network drive,then you got an exception>

This post BY YOU would indicate that you are NOT running your code on the same machine as the database, which is the reason I suggested a permission issue, and the reason Steve wants to verify your environment. If you aren't sure where your code is running, or you can't properly explain the environment, then how do you expect us to be able to assist you.

It's a simple question, but apparently you'd rather answer with snide comments.

Good luck with your project ...

Avatar of cctest

ASKER

Thank you all for your suggestions. Besides using the new connection string, I have to install the 2007 Office System Driver: Data Connectivity Components which can be found at http://www.microsoft.com/downloads/details.aspx?FamilyID=7554f536-8c28-4598-9b72-ef94e038c891&DisplayLang=en

Avatar of cctest

ASKER

This is the one that perfectly work for me:
<add name="CCs" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=&quot;D:\Documents\CCs.accdb&quot;" providerName="System.Data.OleDb"/>
If I take off the providerName, it doesn't work. FYI.