11

How to determine (for a machine running windows xp/vista/7) whether ACE or JET is installed, so I can use an appropiate connection string to connect to a access database.

willem
  • 2,617
  • 5
  • 26
  • 38
  • 2
    Jet is always installed. The question is really only whether or not ACE is installed. – David-W-Fenton Mar 17 '11 at 03:56
  • 1
    I think tag "ACE" is not appropriate here, because most of developers including myself think of Adaptive Communication Environment (http://www.cse.wustl.edu/~schmidt/ACE.html) when they see "ACE" which has nothing to do with your question. – Alexei Polkhanov Mar 26 '11 at 18:36
  • I have been trying to get a better tag than Jet (which overlaps with more than one completely different technology, and is also not accurate when it's the ACE instead of Jet involved), but nobody supports it. – David-W-Fenton Apr 09 '11 at 22:55

3 Answers3

8

There is a registry key you can check. It is at HKCR\Microsoft.ACE.OLEDB.12.0. You can read it using the RegistryKey class.

5

Agreed, the Registry is not the best method (32 and 64-bit versions as well as user permissions, etc.) However, the original question stated "use an appropiate connection string" - this is a runtime issue, not a compile-time issue. A solution might be to use the OleDbEnumerator.

Here is an example that checks for the 32-bit version of Microsoft Access (ACE 12.0). for an x86 application:

using System.Data;
using System.Data.OleDb;

    static bool AceOleDb12Present()
    {
        OleDbEnumerator enumerator = new OleDbEnumerator();
        DataTable table = enumerator.GetElements();
        bool bNameFound = false;
        bool bCLSIDFound = false;

        foreach (DataRow row in table.Rows)
        {
            foreach (DataColumn col in table.Columns)
            {
                if ((col.ColumnName.Contains("SOURCES_NAME")) && (row[col].ToString().Contains("Microsoft.ACE.OLEDB.12.0")))
                    bNameFound = true;
                if ((col.ColumnName.Contains("SOURCES_CLSID")) && (row[col].ToString().Contains("{3BE786A0-0366-4F5C-9434-25CF162E475E}")))
                    bCLSIDFound = true;
            }
        }
        if (bNameFound && bCLSIDFound)
            return true;
        else
            return false;
    }
Derek Johnson
  • 927
  • 1
  • 11
  • 15
3

Note that the RegistryKey may be there but the OleDb connection can still fail because of 32bit / 64bit issues. If the target machine has 32bit ACE.OLEDB installed then make sure the app is compiled to target 32bit CPU. Otherwise the app may run in 64bit (on a 64bit OS) and then cannot load the 32bit installed version of ACE.OLEDB.

Steve
  • 69
  • 3