So I'm coding an application to help monitor ODBC connections for my work. The idea is basically to connect in to ODBC connection and just write the results to a text file every X minutes.
However, finding a way to enumerate ODBC DSNs proved to be difficult. Turns out there's no API for it.. you have to manually tear the DSN information out of the registry. Here's the code I wrote... I have an arraylist I populate with instances of an 'ODBC' object which is just a custom object to hold the data. Nothing too complicated, but just for the hell of it I'll post the code for the object too.
And here's the code for the part that generates the ODBC DSN list.
This code works though I'm not through coding the app yet. The code may end up changing depending on what I need and roadblocks I may run into. Also note that I'm only recording DSNs that contain Driver and Server strings/dwords. Not all DSNs do (such as Excel) so these wouldn't be added to the enumerated DSN list. This also only enumerates system DSNs... user DSNs are stored in a different part of the registry.
*edit* Fixed a typo in the class name. It's DSN, not DNS.