Page 1 of 1

Detecting ODBC Drivers

PostPosted: Thu Aug 29, 2013 4:10 pm
by stu
So far I have seen 4 diferent versions for the same ODBC driver installation:

5.2w
5.2a
5.2
5.2 ANSI

So its really hard to preconfigure an application to work with some sort of default value in this matter. Is there a way to obtain the version of the drivers though registry or something like this?

Re: Detecting ODBC Drivers

PostPosted: Fri Aug 30, 2013 3:08 am
by dec
Hello,

Welcome to this forum. I never installed an ODBC driver (consciously) , however, in my system (Windows 8 ) a Windows Registry exists which apparently provide information about the installed ODBC drivers. Take a look at this key under "HKEY_LOCAL_MACHINE":

Code: Select all
Software\ODBC\ODBCINST.INI\ODBC Drivers


This key contain the subkey named "ODBC Drivers", which contain all the ODBC drivers installed. Every value in "ODBC Drivers" correspond with another subkey, which contain itself the "DriverODBCVer" value name, which contain the version of the ODBC driver.

You can use my npConf plugin to work with the Windows Registry in an advanced way, so, as you can see in the publication sample I attached bellow, it's more or less easy to retrieve the data that you wanted from the Windows Registry. Take a look if you like.

http://neoplugins.com/?download/odbcdrivers.zip

Also I wanted to add here the code really used in the above publication sample, because maybe someone glad to read it here directly:

Code: Select all

.Create our Registry object instance
npRegCreate "[RegID]"

.We need to open the Registry only to read (this is needed
.because LOCAL_MACHINE cannot be open in write mode if we are
.not adminitrators)
npRegAccessKey "[RegID]" "KEY_READ" "[Result]"

.Specify the LOCAL_MACHINE root key
npRegRootKey "[RegID]" "HKEY_LOCAL_MACHINE" "[Result]"

.Open the ODBC Drivers key (we omit in this sample the errors comprobation)
npRegOpenKey "[RegID]" "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" "False" "[Result]"

.Get all the installed drivers, which are saved as subkeys
npRegValueNames "[RegID]" "[InstalledDrivers]" "[InstalledDriversCount]"

.Close the opened key, we no need more
npRegCloseKey "[RegID]" "[Result]"

.Iterate over all the retrieved installed drivers
Loop "0" "[InstalledDriversCount]-1" "[I]"

  .For our convenience
  SetVar "[DriverName]" "[InstalledDrivers[I]]"

  .Open the individual ODBC driver registry key
  npRegOpenKey "[RegID]" "SOFTWARE\ODBC\ODBCINST.INI\[DriverName]" "False" "[Result]"

  .Read the value who contain the driver version
  npRegReadValue "[RegID]" "DriverODBCVer" "[DriverVersion]"
 
  .And, in this case, add the Driver name/version into a ListBox object
  ListBoxAddItem "DriversListBox" "0" "Driver [#34][DriverName][#34] - Version: [#34][DriverVersion][#34]"

  .Close the opened key
  npRegCloseKey "[RegID]" "[Result]"
EndLoop

.Free our Registry instance
npRegDestroy "[RegID]" "[Result]"

Re: Detecting ODBC Drivers

PostPosted: Sun Sep 01, 2013 4:42 pm
by stu
Works ok, thanks for the explanation... I though it could be more simple... Thanks again!

Re: Detecting ODBC Drivers

PostPosted: Sun Sep 01, 2013 4:46 pm
by dec
stu wrote:Works ok, thanks for the explanation... I though it could be more simple... Thanks again!


You're welcome! Maybe another mate can tell us a more easy way to do it. ;)

Re: Detecting ODBC Drivers

PostPosted: Tue Sep 03, 2013 9:03 am
by dpayer
stu wrote:So far I have seen 4 diferent versions for the same ODBC driver installation:
5.2w
5.2a
5.2
5.2 ANSI
So its really hard to preconfigure an application to work with some sort of default value in this matter. Is there a way to obtain the version of the drivers though registry or something like this?


Is your question which ODBC driver is used or which database it is connected to? Won't your system use whichever ODBC is installed (everything since XP had some form of driver installed) then the real issue is to what database is it connected. From there you can run your app.

What are you hoping to get done?

David P

Re: Detecting ODBC Drivers

PostPosted: Wed Sep 04, 2013 2:51 pm
by stu
No, its just that I make a test program (just starting with NBDBPro) and so I connect to a MySql Database hosted on Justhost. In the config string I had "ODBC 5.2w" it worked ok, then I try on another computer so I downloaded ODBC connector again and installed, It didnt worked until I manually check the registry and realized that the installed drivers where "ODBC 5.2 ANSI" I input that and it worked fine, then same thing on another computer and you might not belive this but again the same problem, this time I had to input "ODBC 5.2a" and so far I know that there is "ODBC 5.2" and also "ODBC 5.2 Unicode". I have no clue why is that it install diferent "versions" on diferent computers, so I was trying to solve this "issue" before doing any software that I could sell. Thought It would be great if somehow you could autoinput the ODBC version in the string once you install the software. Other thing will be to check if the connector is installed in the local machine, figure you should use registry values for that aswell. NPCONF seems to be the solutions for both problems... (?)

Re: Detecting ODBC Drivers

PostPosted: Wed Sep 04, 2013 3:09 pm
by dec
Hello,

stu wrote:No, its just that I make a test program (just starting with NBDBPro) and so I connect to a MySql Database hosted on Justhost. In the config string I had "ODBC 5.2w" it worked ok, then I try on another computer so I downloaded ODBC connector again and installed, It didnt worked until I manually check the registry and realized that the installed drivers where "ODBC 5.2 ANSI" I input that and it worked fine, then same thing on another computer and you might not belive this but again the same problem, this time I had to input "ODBC 5.2a" and so far I know that there is "ODBC 5.2" and also "ODBC 5.2 Unicode". I have no clue why is that it install diferent "versions" on diferent computers, so I was trying to solve this "issue" before doing any software that I could sell. Thought It would be great if somehow you could autoinput the ODBC version in the string once you install the software. Other thing will be to check if the connector is installed in the local machine, figure you should use registry values for that aswell. NPCONF seems to be the solutions for both problems... (?)


I have not too much experience with databases, but, I think the approach is to "try to connect". Better said, not to specify in any place the version of the driver we want to use, but instead this, use the latest available version available. Then, if you have problems during connect or something, you can tell the user about the problem. Of course can be a good idea to search into the Registry, but, I want to say that you maybe can omit the version information into the connection strings, so your application just try to use the appropiate driver and not an specific driver version.

Hope you can understand me and this can help you in some manner. ;)