0

I have a C# WPF app that needs to automate the creation of an Access 2016 database.

It executes the following code:

try
            {
                var tempDb = new Access.Application();
                tempDb.OpenCurrentDatabase(tempDbPathFile);

On the line for OpenCurrentDatabase the following exception is raised:

System.AccessViolationException occurred HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=Microsoft.Office.Interop.Access StackTrace: at Microsoft.Office.Interop.Access.ApplicationClass.OpenCurrentDatabase(String filepath, Boolean Exclusive, String bstrPassword) at AccessLauncher.WPF.Launcher.ExportFormsAndQueries(String tempDbPathFile, String userDbPathFile)

I'm not using interop for Access97 - just for Access2016. The only interaction the app has to make with 97 is to copy an existing empty 97 database to a local folder then populate it by selecting into from Sql Server via an OleDbCommand.

I have tried the same code on several PCs and I only get the error on PCs that have both Access2016 and Access97 installed. Unfortunately, this is a requirment since the application must be able to create different databases in both formats - which users subsequent open (in either Access97 or Access2016 as appropriate) to edit.

Any ideas how this could be resolved?

Rob Bowman
  • 7,632
  • 22
  • 93
  • 200
  • probably DLL hell with the added benefits of 32bit/64bit interop. the 97 in Access 97 is 1997, that is *more than 20 years ago* are you sure you need to support that :-) --> [maybe related](https://stackoverflow.com/a/14982382/1132334), especially the connection string details in its accepted answer – Cee McSharpface Apr 30 '18 at 18:55
  • Yes, I'm afraid the app needs to work with Access97 - even though it's older than I'd like to be. – Rob Bowman Apr 30 '18 at 18:58
  • Are you using an interop assembly for Access 97??? Typically you'd be using a PIA for the earliest version you need to support, and it "just works".. I would expect issues with a PIA for 2016 running in 2010, ...let alone 97. – Mathieu Guindon Apr 30 '18 at 18:59
  • I'm not using interop for Access97 - just for Access2016. The only interaction the app has to make with 97 is top copy an existing "empty" 97 database to a local folder then populate it by selecting into from Sql Server via an OleDbCommand – Rob Bowman Apr 30 '18 at 19:02
  • I'd try generating an interop assembly from Access97 (assuming that's possible?), and code against *that*. IMO an Access97 interop library is more likely to work with Access 2016 than seeing the Access 2016 interop working with Access97. – Mathieu Guindon Apr 30 '18 at 19:14

1 Answers1

1

Access_2013 dropped support for the Access_97 file format. Some people have reported that Access_2016 is even more insistent on having absolutely nothing to do with Access_97 files.

This question discusses the issue in more detail. TL;DR: A business application that requires support for both Access_2016 and Access_97 is

  • obviously not an officially supported configuration, and
  • likely to be a source of ongoing headaches if it can be made to work at all.

My advice: Bite the bullet and migrate away from the Access_97 file format.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • I have no choice but to use Access97 because third party software needs to work against this. The vendor insists it must be Access97, they will not update their code to work against a more recent version – Rob Bowman May 10 '18 at 18:49