How do I programatically get the name of an ODBC driver’s DLL file for a given ODBC driver. For example, given “SQL Server Native Client 10.0” I want to find the name of that driver’s DLL file: sqlncli10.dll. I can see this in REGEDIT in the “Driver” entry in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI. If I try to read the value from the registry in my code it returns an empty string. I also tried using the ODBC API function SQLDrivers. The code below successfully returns all the values of the attributes in the Attribs variable except “Driver”. Everything is there – APILevel, ConnectFunctions, CPTimeout, etc – but “Driver” is not in the list.
repeat
Status := SQLDrivers (HENV, SQL_FETCH_NEXT, PAnsiChar(DriverName), 255,
NameLen, PAnsiChar(Attribs), 1024, AttrLen);
if Status = 0 then begin
List.Add(DriverName);
List.Add(Attribs);
end;
until Status <> 0;
You can use
SQLGetInfo()withInfoType=SQL_DRIVER_NAMEI hope this will look like:
But this function works with already connected database.
I tried
SQLDrives()and you are right: in my environment this function also do not return DLL name. So I tried to read it from registry and it worked this way:For driver:
IBM INFORMIX ODBC DRIVERI got:C:\informix\bin\iclit09b.dllFor driver:
SQL ServerI got:C:\WINDOWS\system32\SQLSRV32.dllRegGetStringDirect()is my function based on Windows API to read something from registry.EDIT:
Two functions to read “SQL Server” ODBC driver dll name by Ron Schuster moved from comment: