Enumerate List of ODBC DSNs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bernie Hunt

    Enumerate List of ODBC DSNs

    I'd like to read a list of the ODBC DSNs set up on the computer. I thought I
    have seen how to do this but I can't seem to dag it. Can anyone help?

    Thanks,
    Bernie


  • JB

    #2
    Re: Enumerate List of ODBC DSNs

    On 8 Jul, 00:59, "Bernie Hunt" <bh...@optonlin e.netwrote:
    I'd like to read a list of the ODBC DSNs set up on the computer. I thought I
    have seen how to do this but I can't seem to dag it. Can anyone help?
    >
    Thanks,
    Bernie
    VoilĂ ...

    'API to obtain list of ODBC connections
    Private Declare Function SQLAllocEnv Lib "ODBC32.DLL " (ByRef env As
    Integer) As Short
    Private Declare Function SQLFreeHandle Lib "odbc32.dll " (ByVal
    handleType As Short, ByVal Handle As Integer) As Short
    Private Declare Function SQLDataSources Lib "ODBC32.DLL " (ByVal
    WindowHandle As Integer, ByVal Direction As Short, ByVal DSNBuffer As
    String, ByVal DSNBufferLength As Short, ByRef DSNLength As Short,
    ByVal DESCBuffer As String, ByVal DESCBufferLengt h As Short, ByRef
    DESCLength As Short) As Short


    Public Shared Sub LoadDSNList(ByV al ComboBoxCtrl As ComboBox)
    Const SQL_BUFFER_SIZE As Short = 1024
    Const SQL_SUCCESS As Short = 0
    Const SQL_SUCCESS_WIT H_INFO As Short = 1
    Const SQL_FETCH_FIRST As Short = 1
    Const SQL_HANDLE_ENV As Integer = 1

    Dim env, RetInt As Integer
    Dim RetShort As Short = SQL_SUCCESS
    Dim BufferDSN, BufferDesc As String
    Dim LengthDSN, LengthDesc As Short
    Dim DSNName As String

    ComboBoxCtrl.It ems.Clear()

    RetInt = SQLAllocEnv(env )
    If (RetInt = SQL_SUCCESS) Or (RetInt = SQL_SUCCESS_WIT H_INFO) Then
    'Get the DSN names & descriptions
    While (RetShort = SQL_SUCCESS) Or (RetShort =
    SQL_SUCCESS_WIT H_INFO)
    BufferDSN = Space(SQL_BUFFE R_SIZE)
    BufferDesc = Space(SQL_BUFFE R_SIZE)
    RetShort = SQLDataSources( env, SQL_FETCH_FIRST , BufferDSN,
    SQL_BUFFER_SIZE , _
    LengthDSN, BufferDesc,
    SQL_BUFFER_SIZE , LengthDesc)

    DSNName = BufferDSN.Subst ring(0, LengthDSN)
    If (DSNName <Space(LengthDS N)) Then
    ComboBoxCtrl.It ems.Add(DSNName )
    End While

    SQLFreeHandle(S QL_HANDLE_ENV, env)
    env = Nothing
    End If

    If (ComboBoxCtrl.I tems.Count < 1) Then
    ComboBoxCtrl.It ems.Add(My.Reso urces.S_MISC_NO _ODBC_CONNECTIO NS_AVAILABLE)
    End Sub

    Comment

    • JB

      #3
      Re: Enumerate List of ODBC DSNs

      On 8 Jul, 00:59, "Bernie Hunt" <bh...@optonlin e.netwrote:
      I'd like to read a list of the ODBC DSNs set up on the computer. I thought I
      have seen how to do this but I can't seem to dag it. Can anyone help?
      >
      Thanks,
      Bernie
      I've posted a reply a couple of hours ago and it still doesn't show...

      Comment

      • JB

        #4
        Re: Enumerate List of ODBC DSNs

        Still not showing...

        Comment

        Working...