1
votes

I need to export data into an Access database. My code works, but it works with the assumption the client machine has the Microsoft.Jet.OLEDB.4.0 as a valid provider.

I want to test to see if this is true or not, in code. My problem is that I don't have the location of an existing access database and I don't want to create a new .mdb that I'd use to verify the connection and then delete it.

Is there any way to tell which providers are installed?

5
+1, if someone down vote, at least give a reason why, so user can edit his question!Itay Moav -Malimovka
While I wouldn't down vote this, the title needs fixed bad. Try a little harder next time will you? :)mmcdole

5 Answers

3
votes

You could simply check for the existence of

HKEY_CLASSES_ROOT\CLSID\{dee35070-506b-11cf-b1aa-00aa00b8de95}

which is the CLSID of Microsoft.Jet.OLEDB.4.0.

2
votes

you could try to detect the MDAC version on the machine and based on that extrapolate if your provider is supported?

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=47262&lngWId=1

here's a snippet you can take a look at.

1
votes

Each major provider has classid mentioned under the registry editor Ex:- HKEY_CLASSES_ROOT\CLSID{dee35070-506b-11cf-b1aa-00aa00b8de95}

which is the CLSID of Microsoft.Jet.OLEDB.4.0.

To check programmatically, use below c# code, its checked on framework 2.0

using System.Data.OleDb;
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_CLSID")) && (row[col].ToString().Contains("{dee35070-506b-11cf-b1aa-00aa00b8de95}")))
                    Console.WriteLine("CLSID of Microsoft.Jet.OLEDB.4.0. Found");

                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)
            Console.WriteLine("Microsoft.ACE.OLEDB.12.0 Not found");
        else
            Console.WriteLine("Microsoft.ACE.OLEDB.12.0 found");

Remember "Fix it right & not let the test bugs bite"

0
votes

I believe if you have the .NET Framework installed (needed to run VB.NET Code) then the machine has the provider you mention. MSDN

0
votes
       Dim reader As Object = OleDbEnumerator.GetRootEnumerator()
        Dim Oleprovide As String = ""

        While reader.Read
            For i = 0 To reader.FieldCount - 1
                If reader.GetName(i) = "SOURCES_NAME" Then
                    If reader.GetValue(i).ToString.Contains(".OLEDB.") = True Then
                        Oleprovide = reader.GetValue(i).ToString
                        Exit For
                    End If
                End If
            Next
        End While
        reader.Close()

        Dim MyConnection As OleDbConnection
        MyConnection = New OleDbConnection("Provider=" & Oleprovide & ";Data Source=" & existingFile.FullName & ";Extended Properties=""Excel 13.0 Xml;HDR=Yes""")
        MyConnection.Open()