Solved

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

Posted on 2007-03-31
16
6,411 Views
Last Modified: 2013-12-16
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.
0
Comment
Question by:cctest
  • 5
  • 5
  • 3
  • +2
16 Comments
 
LVL 75
ID: 18829099
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
0
 
LVL 84
ID: 18829387
Can you post the connection string you're using?
0
 
LVL 3

Accepted Solution

by:
fredvr666 earned 125 total points
ID: 18831912
using System.Data.OleDb;

string Sql="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\db1.accdb;Persist Security Info=False;";
OleDbConnection aConnection = new OleDbConnection(Sql);

aConnection.Open();
0
 
LVL 84
ID: 18832007
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 ...
0
 
LVL 3

Expert Comment

by:fredvr666
ID: 18832091
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

0
 
LVL 84
ID: 18832337
<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?
0
 
LVL 3

Expert Comment

by:fredvr666
ID: 18832492
<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;";
0
 
LVL 84
ID: 18832578
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.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 3

Expert Comment

by:fredvr666
ID: 18832652
it's not the database file, if you read the example it's on C:\.
It's the application!
0
 
LVL 75
ID: 18832656
Where is 'cctest' ?
0
 
LVL 39

Expert Comment

by:stevbe
ID: 18835671
<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?
0
 
LVL 3

Expert Comment

by:fredvr666
ID: 18838553
stevbe your rank is genius, can you read?
0
 
LVL 84
ID: 18839258
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 ...

0
 

Author Comment

by:cctest
ID: 18903731
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

0
 
LVL 75
ID: 18903748
wow ... hang tuff LSM ... :-)

mx
0
 

Author Comment

by:cctest
ID: 18903943
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.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now