How to check if an OLEDB driver is installed on the system?
Solution 1
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;
Solution 2
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;';
Solution 3
You can get a ADO provider name and check it in registry at path HKEY_CLASSES_ROOT\[Provider_Name].
Solution 4
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.
Related videos on Youtube
Karl-Otto Rosenqvist
A software developer that likes to create small utillities that makes life easier. Have two kids that I haven't been able to change the source code for so I have to adjust my own to be able to be a good parent!
Updated on July 09, 2022Comments
-
Karl-Otto Rosenqvist almost 2 years
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 driver is missing. The error that's returned from ADO isn't always that user-friendly.
There are probably a nice little function that returns all installed drivers but I haven't found it.
-
mistertodd almost 4 yearsJust to make sure, and for everyone else coming later, if you're using ADO, and you do decide to use the modern
MSOLEDBSQL
driver (or the olderSQLNCLI11
,SQLNCLI10
,SQLNCLI
drivers), be sure to includeDataTypeCompatibility=80
in your connection string. ADO doesn't understand some of the newerDBTYPE_xxx
constants that the modern drivers will return; and Microsoft is committed to not updating ADO - so no fixes coming. Hence by the SQL Server team addedDataTypeCompatibility
connection string option. MSDN: Using ADO with SQL Server Native Client
-
-
James L. over 11 yearsNice of you to post the answer -- even though it's literally years later.