njshaw2
Posts: 26
Joined: Fri Apr 19, 2013 10:36 am

Find which MySQL ODBC driver is installed?

My installer needs to run an SQL ODBC test. This is done as a custom event using the built-in TestSqlConnection custom event. The [SqlConnectionString] parameter, however, has to be filled in with the MySQL ODBC driver name, e.g. "Driver=[\{]MySQL ODBC 5.1 Driver[\}];Server=[HOSTNAME];Port=[PORT];Uid=[USER];Pwd=[PASSWORD];".

If the installer runs on a PC that has this version of the MySQL ODBC driver on it, the installer does the job perfectly. However, if the PC being installed onto has a different version of the MySQL ODBC driver (say v5.2w) this custom action fails as it can't find the driver for v5.1.

Is there therefore any way to do the following?:
1) Detect which version of the MySQL ODBC driver is installed;
2) Use that in the custom string above.

I can't find any registry key or file that contains the required information. The registry does have the key HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB\MySQL Connector/ODBC 5.2(w), containing the setting Version, but I can't search for that registry key as the key itself contains the version number. There's also the registry key HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\MySQL ODBC 5.2w Driver, but again that contains the version number as part of the key itself.

So is there any way to enumerate a number of registry keys and match on the one containing the text "MySQL ODBC" in it?... Other than in a 3rd party DLL that is?

Thanks,
Nick.
Daniel
Posts: 8276
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Find which MySQL ODBC driver is installed?

Hello Nick,

I'm afraid we don't have predefined support for this. However, as a workaround you can proceed like this:
- Go to "Search" page and create a new extended search (e.g. FIND_DRIVER) like this:
  • Criteria: Registry SubKey enumeration
    Registry Key: HKLM\SOFTWARE\ODBC\ODBCINST.INI
- Create your own custom action which will parse the FIND_DRIVER property and will set another property (e.g. DRIVER_FOUND) accordingly if an ODBC driver is found. Add the custom action after "Searches" action group.
- Set the [SqlConnectionString] property like this:

Code: Select all

Driver=[\{][DRIVER_FOUND][\}];Server=[HOSTNAME];Port=[PORT];Uid=[USER];Pwd=[PASSWORD];
- Build and run your project.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
njshaw2
Posts: 26
Joined: Fri Apr 19, 2013 10:36 am

Re: Find which MySQL ODBC driver is installed?

Thanks Daniel, I'll give that a try!

Return to “Building Installers”