09-22-2014 03:12 PM
Does anyone know of a way to query the available system DSN names on a Windows PC? Ideally, the list would be returned in a array of strings. Also, is there a way to determine what DB file and path is associated with each system DSN name?
Solved! Go to Solution.
09-22-2014 04:27 PM
Yes, this information is found in the registry. Use the built in registry VIs to access.
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\
09-22-2014 04:37 PM
They are simply in the registry. So enumerating the registry HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources will give you all the according entries and then enumerating HKLM\SOFTWARE\ODBC\ODBC.INI\%s where the %s is replaced with the DSN name from before will give you the different connection settings.
Watch out! The system DSNs are seperated into 32 bit and 64 bit Data Sources and configured in seperate versions of the ODB Manager. You have to access the right registry hive. Newer LabVIEW versions allow you do select if the default, WOW64_32 or WOW64_64 hive should be opened. They correspond to the default hive for whatever bitness your current application is, the 32 Bit hive or the 64 bit hive respectively.
09-22-2014 04:54 PM
Thanks for the tip ROLFK...I was querying the key and getting data that wasn't there.
09-23-2014 04:53 AM - edited 09-23-2014 04:54 AM
By the way, unless the used driver is some native OLEDB driver you won't be able to use DSNs that you don't see when not using the default registry hive selection. These DSNs use DLL drivers that the ODBC driver loads and have to match the bitness of the calling application. Otherwise you get some not so intelligent error messages back from the ODBC manager that the driver could not be found but it's not so much that it can't find it than more about not being able to load it, since it doesn't match the environment your application runs in.
09-23-2014 09:52 AM
Aputman, Rolfk:
Thanks so much for your response. I coded the picture you provided, but I received an error message:
Remote registry access denied.
Is there some Windows setting that needs to be changed? I thought I was the admin of my computer, so I don't know that it's a rights issue.
09-23-2014 09:57 AM
Change the KEY_WOW64_64KEY to default or 32KEY.
09-23-2014 04:45 PM - edited 09-23-2014 04:47 PM
Also note that the Open Registry Key.vi has a default security access mask of KEEY_READ AND KEY_WRITE access. HKLM however is for the most part a fully privileged registry part that you can only open for write access with administrative access rights. Try to open the key with only KEY_READ rights. That's enough to enumerate and read subkeys of a key. If you need to change them, you have to open the key with KEY_WRITE too, but that only succeeds if your process was started as administrator.
If you need to change any values in HKLM you need to open the key with KEY_WRITE access but that only succeeds if the process was started as administrator.
09-24-2014 08:50 AM
Aputman:
Thanks for the tip. I found another way a getting around the error. In Open Registry Key, I feed in a KEY_READ constant into the security access mask input. The error is no longer triggered.
Is there another key or subkey that will return the actual path/names of the DB files, rather than their system DSN names? Thanks.
09-24-2014 08:53 AM
Rolf:
On careful reading of your response, I see that you suggested using KEY_READ in Open Registry Key. It works. I found this independently, but it shows I should be more careful when people take the time to respond. Thanks again.