Solved

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

Posted on 2007-03-31
16
6,423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 85
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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
LVL 85
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 85
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 85
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
 
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 85
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

628 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