c# Program gets an error using Microsoft.Jet.OLEDB.4.0 after connection open MDAC 2,6 or later is required

272 Views Asked by At

An old C# program no longer works to read an MS-Access database through Jet.OLE.DB. Also a new compilation without any changes of the source code didn't help.

My laptop is running Windows 10 and the MS Office is LTSC Professional Plus 2021 32-bit.

I uninstalled Office LTSC 64-bit to install Office LTSC 32-bit and am trying to fix the problem installing the following recommended runtime packages:

  1. AccessDatabaseEngine.exe
  2. mdac28sdk.msi
  3. AccessRuntime2007.exe
  4. AccessRuntime_x86_en-us.exe

Our customer uses MS Access because he has linked thousands of macros in Excel with Access and switching to other databases is not possible.

1

There are 1 best solutions below

0
MarcSS On

It wasn't possible to use OLE in the current Windows 10 OS 64bit environment and that's why I switched to ODBC and it works.

I gave up using Visual Studio 2022 and switched to ACE for now because VS 2022 is really weird. I tried updating the current VS 2017 project but I couldn't select a NET Frame higher than 4.8. I created a new project and then I could select NET 6 or 7 if I would select "Windows Forms App" instead of "Windows Forms App (NET Framework)" but the toolbox is empty.

  /*old code*/
  string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Datenbank + ";";
  OleDbConnection  conn = new OleDbConnection(connStr);
  String strCommand = "SELECT * FROM Tickets WHERE [Ticket_Nummer] = @Ticket_Nummer";
  OleDbDataAdapter da = new OleDbDataAdapter(strCommand, conn);
  da.SelectCommand.Parameters.Add("@Ticket_Nummer", OleDbType.Integer).Value = Ticket_Nummer;
  /*new code*/
  string connStr = "Driver={Microsoft Access Driver (*.mdb)};"
      + "Dbq="+ Datenbank+";Uid=Admin;Pwd=;";
  OdbcConnection conn = new OdbcConnection(connStr);
  String strCommand = "SELECT * FROM Tickets WHERE [Ticket_Nummer] = ?";
  OdbcDataAdapter da = new OdbcDataAdapter(strCommand, conn);
  da.SelectCommand.Parameters.Add("@Ticket_Nummer", OdbcType.Numeric).Value = Ticket_Nummer;
  /*rest code*/
  DataSet  DataSet = new DataSet();
  da.Fill(DataSet, "TICKET");
  DataTable dataTable = DataSet.Tables[0];
  DataTableReader  dr = new DataTableReader(dataTable);