0

I recently had a new project assigned to me (I'm new to C# and I'm a junior). It makes use of a Microsoft access database file (.accdb file)

I've imported the project into Visual Studio but I can't for the life of me run the code. Initially I had file register issues, and I think I managed to resolve that by getting the IT teams to install a "2007 Office System Driver: Data Connectivity Components" driver from the Microsoft website.

Bow the error says:

System.Data.OleDb.OleDbExceptions: 'Cannot open database''. It may not be a database that your application recognizes, or the file may be corrupt.'

The team I'm trying to help only has one dev (working from a different country) who is the main person to handle the code. It works on her side, but she doesn't really have the experience to help me troubleshoot this.

I tried sending her my database file, for her to swap her file for mine, and she said it was still working, so it sounds like the issue might not be to do with the file?

Could I get any help if possible? So far my only approach is to keep googling the error.

But the only resolutions I see are from people who have database files nearing their file size limit (2GB). My database file is just 1MB.

The database file is password protected (the password happens to be in the code). I opened the database file (Microsoft access opens) and entered the password and I had no issue accessing the data)

CaptainObv
  • 360
  • 1
  • 4
  • 15
  • 1
    What's the code that's opening the file? – Ben Feb 04 '19 at 03:08
  • 1
    Please don't ask questions about code without posting the code. Is your colleague using the same code? Here's an example of code connecting to ACCDB https://stackoverflow.com/questions/33642446/simple-c-sharp-connection-to-accdb-file does your look like this? Does it have a simliar connection string? Specifically `Provider=Microsoft.ACE.OLEDB.12.0`. You might need to install the ACE driver. – Nick.Mc Feb 04 '19 at 03:15
  • Solving coding problems is often just taking pieces out until you isolate the issue more specifically. So I suggest first just try connecting to a blank ACCDB - does that work? If so the next thing to do is try removing the password from your ACCDB and try that. If not, then it doesn't have anything to do with your specific ACCDB – Nick.Mc Feb 04 '19 at 03:16
  • What is your connection string? – jdweng Feb 04 '19 at 03:17
  • The ace driver I had already installed initially. The issue really was to do with the database file. I created a new one and imported everything and it seems to be working now – CaptainObv Feb 04 '19 at 03:25

1 Answers1

1

Out of luck, I managed to find the right article to help me!

The issue with Microsoft access database files is only one user can really use then at a time I believe.

I saw a forum about potential locks made by other users. I googled how to remove locks but it seems that it might not be a lock issue (Microsoft creates a lock file which I dont have).

Regardless, I assumed that the issue is still somewhat similar. Since I had access to the database in Microsoft Access, I decided to open a new database, then go to external data tab and click on access to import EVERYTHING from the other file. Then I just renamed to old file and give my new file the original name.

I reran the code and it worked!

I dont know why the other dev had no issue opening the file. My assumption is that because she is the only developer her laptop is already 'set up' in some way to run everything as normal, whereas if someone new tried (or if something happens and she has to re-open the code on a new laptop) they would have to try and replicate the 'set up' or try and work from scratch

Hope this helps

CaptainObv
  • 360
  • 1
  • 4
  • 15
  • I don't know why people had to give you down votes! I came across this problem today, and I recreated the database - it worked! Thank you very much! – machnine Dec 23 '19 at 12:22