I have been looking for several hours for code that automatically checks if Microsoft acess database engine is installed. If not it reinstalls the database driver by first detecting architechture(32/64 bit). It then automatically installs the driver. I am using Ms Access database 2007 as data source for my app but this just came up after I realized that it won't run on a computer without a Access installed.

I figured out the code to detect if the engine is not installed but am not sure if its foolproof. Here is what I thought would be good detecting if engine is installed

                using (OleDbConnection conn = new OleDbConnection(databaseConnString.GetConnectionString))
catch(InvalidOperationException ioex)
//Here is where I want to install the Database engine //since this exception means engine isn't installed

Please help provide me with code to detect architecture (32/64 bit ) then install the relevant engine. I have downloaded db engines for both 32 and 64 bit.

Thanks in advance.

Edited by pritaeas: Moved to C#.

2 Years
Discussion Span
Last Post by cgeier

Add using statement:

  • using Microsoft.Win32;

Then to find out if it is 32-bit (x86) or 64-bit:

private string processorArchitectureKey = @"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment";

private string productVersionKey = @"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion";


string processorArchitecture = Registry.GetValue(processorArchitectureKey, "PROCESSOR_ARCHITECTURE", null).ToString();
Console.WriteLine("Processor Architecture: " + processorArchitecture);

string osVersion = Registry.GetValue(productVersionKey, "ProductName", null).ToString();
Console.WriteLine("OS: " + osVersion);

Edited by cgeier

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.