How to check if an OLEDB driver is installed on the system?

前端 未结 6 1911
走了就别回头了
走了就别回头了 2020-12-06 16:59

How can I make sure that a certain OLEDB driver is installed when I start my application? I use ADO from Delphi and would like to display a descriptive error message if the

相关标签:
6条回答
  • 2020-12-06 17:05
    namespace Common {
      public class CLSIDHelper {
    
      [DllImport("ole32.dll")]
      static extern int CLSIDFromProgID([MarshalAs(UnmanagedType.LPWStr)] string lpszProgID, out Guid pclsid);
    
    
      public static Guid RetrieveGUID(string Provider) {
        Guid CLSID = Guid.Empty;
        int Ok = CLSIDFromProgID(Provider, out CLSID);
        if (Ok == 0)
           return CLSID;
        return null;
      }
     }
    }
    
    0 讨论(0)
  • Wouldn't the easiest way just be trying to make a connection at start-up and catching the error?

    I mean you might get a few different errors back depending on, for example, the user is online, but they're cases that you should be able to test for.

    0 讨论(0)
  • 2020-12-06 17:15

    I believe the OLEDB objects in question are buried someplace in the registry, since OLEDB / ADO is a COM solution. My guess would be to see if you can find the GUID that your driver is installed as in the registry.

    0 讨论(0)
  • 2020-12-06 17:17

    This is an old question but I had the same problem now and maybe this can help others.

    In Delphi 7 there is an procedure in ADODB that return a TStringList with the provider names.

    Usage example:

    names := TStringList.Create;
    ADODB.GetProviderNames(names);
    
    if names.IndexOf('SQLNCLI10')<>-1 then
      st := 'Provider=SQLNCLI10;'
    else if names.IndexOf('SQLNCLI')<>-1 then
      st := 'Provider=SQLNCLI;'
    else if names.IndexOf('SQLOLEDB')<>-1 then
      st := 'Provider=SQLOLEDB;';
    
    0 讨论(0)
  • 2020-12-06 17:20

    You can get a ADO provider name and check it in registry at path HKEY_CLASSES_ROOT\[Provider_Name].

    0 讨论(0)
  • 2020-12-06 17:27

    Each provider has a GUID associated with its class. To find the guid, open regedit and search the registry for the provider name. For example, search for "Microsoft Jet 4.0 OLE DB Provider". When you find it, copy the key (the GUID value) and use that in a registry search in your application.

    function OleDBExists : boolean;
    var
      reg : TRegistry;
    begin
      Result := false;
    
      // See if Advantage OLE DB Provider is on this PC
      reg := TRegistry.Create;
      try
        reg.RootKey := HKEY_LOCAL_MACHINE;
        Result := reg.OpenKeyReadOnly( '\SOFTWARE\Classes\CLSID\{C1637B2F-CA37-11D2-AE5C-00609791DC73}' );
      finally
        reg.Free;
      end;
    end;
    
    0 讨论(0)
提交回复
热议问题