Hi,
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

try
            {
                using (OleDbConnection conn = new OleDbConnection(databaseConnString.GetConnectionString))
{
conn.Open();
}
}
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.

Recommended Answers

All 2 Replies

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";

Then:

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.