How to determine if ACE or JET on windows machine using .net?
Asked Answered
H

3

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.

Huntingdonshire answered 16/3, 2011 at 12:28 Comment(3)
Jet is always installed. The question is really only whether or not ACE is installed.Waterlog
I think tag "ACE" is not appropriate here, because most of developers including myself think of Adaptive Communication Environment (cse.wustl.edu/~schmidt/ACE.html) when they see "ACE" which has nothing to do with your question.Galley
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.Waterlog
T
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.

Tenebrae answered 16/3, 2011 at 12:46 Comment(0)
H
6

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;
    }
Hodometer answered 20/7, 2013 at 17:26 Comment(0)
D
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.

Dobsonfly answered 12/11, 2012 at 13:17 Comment(1)
How can you check which architecture (if at all) of the provider is installed?Quern

© 2022 - 2025 — McMap. All rights reserved.