Solved

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

Posted on 2007-03-31
16
6,415 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

911 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

22 Experts available now in Live!

Get 1:1 Help Now