Mani Agarwal
Mani Agarwal

Reputation: 11

How to figure out ODBC Driver name based on SQL Server Version installed in machine?

I am a Database Developer and currently working in SQL Server Technology. I am trying to find out the ODBC driver name based on the installed SQL Server Version. Here is what I mean - Example,

We are using SQLCMD.exe to execute some scripts through our custom MSI. SQLCMD fails if it doesn't find the correct ODBC driver. Hence we need to be able to identify the correct ODBC version based on the SQL version installed, so that we can check this before installation and prompt the user to install the correct ODBC version as a prerequisite.

I have already explored the below -

  1. Windows Registry - I did not get a clear cut idea of how to identify ODBC drivers based on versions. ODBC drivers and SQL Server versions are mentioned at multiple places and either they do not match amongst themselves or with the installed SQL Server Version.
  2. Admistrative Tools -> ODBC Admistrator -> Drivers Tab SQL Server Version here do give some idea but we are unable to decode odbcad32.exe. Link - https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/check-the-odbc-sql-server-driver-version-windows?view=sql-server-2017

If anyone knows anything then please render help. We need a solution using C# ( recommended ), however, if any other technology then we can have a look for its feasibility.

Thanks in advance.

Upvotes: 1

Views: 12484

Answers (1)

Apep
Apep

Reputation: 111

Windows registry is the best way to go, I'm not sure why you're seeing inconsistencies. There are two main places to look:

For 64bit: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers

For 32bit: HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBCINST.INI\ODBC Drivers

If you want the specific version, you will need to go up a level into the registry keys that have the same name as those listed in ODBC Drivers. For exmaple, under ODBC Drivers you have the key "ODBC Driver 17 for SQL Server" listed as installed, under ODBCINST.INI you will have a entry called "ODBC Driver 17 for SQL Server" where you can find further details.

ODBC driver versions aren't intrinsically linked to the version of SQL installed. It's absolutely possible the ODBC driver has been updated separately, and/or multiple versions are installed.

Upvotes: 4

Related Questions