LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

System DSN Names

Solved!
Go to solution

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?

0 Kudos
Message 1 of 10
(3,580 Views)

Yes, this information is found in the registry.  Use the built in registry VIs to access.

HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 10
(3,566 Views)
Solution
Accepted by ScottDobbins1

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.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 10
(3,562 Views)
Solution
Accepted by ScottDobbins1

Example_VI_BD.png

 

Thanks for the tip ROLFK...I was querying the key and getting data that wasn't there.  Smiley Happy

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 4 of 10
(3,555 Views)

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.

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 10
(3,518 Views)

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.

 

 

 

 

0 Kudos
Message 6 of 10
(3,496 Views)

Change the KEY_WOW64_64KEY to default or 32KEY. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 7 of 10
(3,490 Views)

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.

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 10
(3,474 Views)

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.

0 Kudos
Message 9 of 10
(3,452 Views)

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.

0 Kudos
Message 10 of 10
(3,450 Views)