Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi!

I manage to get the DSN from registry. But the column for data unable to retrieve. Can someone help me? Below are my code to find the value of ODBC.

VB
Private Sub GetDSNDetails()
       Dim dsnNames As New List(Of String)
       Dim reg As Microsoft.Win32.RegistryKey = Registry.LocalMachine.OpenSubKey("Software")
       If reg IsNot Nothing Then
           reg = reg.OpenSubKey("ODBC")
           If reg IsNot Nothing Then
               reg = reg.OpenSubKey("ODBC.INI")
               If reg IsNot Nothing Then
                   reg = reg.OpenSubKey("ODBC Data Sources")
                   If reg IsNot Nothing Then
                       For Each dsn As String In reg.GetValueNames
                           dsnNames.Add(dsn)
                       Next
                   End If
               End If

           End If
       End If

       For Each Name As String In dsnNames
           TextBox1.AppendText("DataSource Name: " & Name & Environment.NewLine)
       Next Name
   End Sub


I need 2 value from ODBC Data Sources at registry. That is Name and Data as image here[^]
Posted

1 solution

Hi,

Try this one,
C#
Dim dsnNames As New List(Of String)
Dim reg As Microsoft.Win32.RegistryKey =      Registry.LocalMachine.OpenSubKey("Software")
If reg IsNot Nothing Then
    reg = reg.OpenSubKey("ODBC")
    If reg IsNot Nothing Then
        reg = reg.OpenSubKey("ODBC.INI")
        If reg IsNot Nothing Then
            reg = reg.OpenSubKey("ODBC Data Sources")
            If reg IsNot Nothing Then
                For Each dsn As String In reg.GetValueNames
                    dsnNames.Add(dsn & "-" & reg.GetValue(dsn))
                Next
            End If
        End If

    End If
End If

For Each Name As String In dsnNames
    TextBox1.AppendText("DataSource Name: " & Name & Environment.NewLine)
Next Name


hope this may help you!!
 
Share this answer
 
Comments
Luiey Ichigo 13-Nov-13 1:13am    
Awesome..it's works...tq :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900