Solved

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

Posted on 2007-03-31
16
6,422 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 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why can't I change data in my query? 3 38
Return Data From Website in Access 6 59
Intermittent OleDbConnection Error 20 53
Export individual report to pdf 2 41
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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