Viewing machine data source names

  • Thread starter Thread starter zdrakec
  • Start date Start date
Z

zdrakec

Hello all:

I want to present my user with a list of all system data source names
(System DSN) that are defined on his machine that are of type MS Access
(.mdb). However, I am having some trouble figuring out how,
programatically, to get access to the ODBC data sources defined on the
user machine.
Can someone point me in the right direction?

Thanks much,
zdrakec
 
zdrakec said:
Hello all:

I want to present my user with a list of all system data source names
(System DSN) that are defined on his machine that are of type MS Access
(.mdb). However, I am having some trouble figuring out how,
programatically, to get access to the ODBC data sources defined on the
user machine.
Can someone point me in the right direction?

Thanks much,
zdrakec

ODBC Data Sources are stored in the Registry. System DSNs are in
HKEY_LOCAL_MACHINE. User DSNs are stored in HKEY_CURRENT_USER (for each
user). From there they are in SOFTWARE\ODBC\ODBC.INI. Look in ODBC Data
Sources for the list, and each in the list will also have a key that
contains the contents of the DSN. Once you find them, it is pretty
obvious how they are stored. And as long as you are comfortable working
with the .NET Registry Class, it's a piece of cake working with them.
 
Thank you zacks:

As it turns out, yes, I had found a way in the manner you describe;
apparently, I needed to post the question before my brain would start
operating on it. I did:

Dim odbcNames() As String =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ODBC\ODBC.INI").GetSubKeyNames
If Not odbcNames Is Nothing AndAlso odbcNames.Length > 0 Then
For Each s As String In odbcNames
Dim valueNames() As String =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ODBC\ODBC.INI").OpenSubKey(s).GetValueNames
If IsInList("FIL", valueNames, True) Then
Dim testVal As String =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ODBC\ODBC.INI").OpenSubKey(s).GetValue("FIL").ToString
End If
Next
End If

Thanks much,

zdrakec
 
zdrakec said:
Thank you zacks:

As it turns out, yes, I had found a way in the manner you describe;
apparently, I needed to post the question before my brain would start
operating on it. I did:

Dim odbcNames() As String =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ODBC\ODBC.INI").GetSubKeyNames
If Not odbcNames Is Nothing AndAlso odbcNames.Length > 0 Then
For Each s As String In odbcNames
Dim valueNames() As String =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ODBC\ODBC.INI").OpenSubKey(s).GetValueNames
If IsInList("FIL", valueNames, True) Then
Dim testVal As String =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ODBC\ODBC.INI").OpenSubKey(s).GetValue("FIL").ToString
End If
Next
End If

Thanks much,

zdrakec

Just remember that the "ODBS Data Sources" sub key is a special sub key
that does not define a DSN, but contains the current list of DSNs.
 
Back
Top