Как получить список всех доступных на машине DSN? - VB
Формулировка задачи:
Subj?
Буду очень признателен за ответ.
Решение задачи: «Как получить список всех доступных на машине DSN?»
textual
Листинг программы
- Option Explicit
- Private Declare Function SQLDataSources Lib 'ODBC32.DLL' (ByVal henv&, ByVal fDirection%, ByVal szDSN$, ByVal cbDSNMax%, pcbDSN%, ByVal szDescription$, ByVal cbDescriptionMax%, pcbDescription%) As Integer
- Private Declare Function SQLAllocEnv% Lib 'ODBC32.DLL' (env&)
- Const SQL_SUCCESS As Long = 0
- Const SQL_FETCH_NEXT As Long = 1
- Sub GetDSNsAndDrivers()
- On Error Resume Next
- Dim i As Integer
- Dim sDSNItem As String * 1024
- Dim sDRVItem As String * 1024
- Dim sDSN As String
- Dim sDRV As String
- Dim iDSNLen As Integer
- Dim iDRVLen As Integer
- Dim lHenv As Long 'handle to the environment
- cboDSNList.AddItem '(None)'
- 'get the DSNs
- If SQLAllocEnv(lHenv) <> -1 Then
- Do Until i <> SQL_SUCCESS
- sDSNItem = Space(1024)
- sDRVItem = Space(1024)
- i = SQLDataSources(lHenv, SQL_FETCH_NEXT, sDSNItem, 1024, iDSNLen, sDRVItem, 1024, iDRVLen)
- sDSN = VBA.Left(sDSNItem, iDSNLen)
- sDRV = VBA.Left(sDRVItem, iDRVLen)
- If sDSN <> Space(iDSNLen) Then
- cboDSNList.AddItem sDSN
- cboDrivers.AddItem sDRV
- End If
- Loop
- End If
- 'remove the dupes
- If cboDSNList.ListCount > 0 Then
- With cboDrivers
- If .ListCount > 1 Then
- i = 0
- While i < .ListCount
- If .List(i) = .List(i + 1) Then
- .RemoveItem (i)
- Else
- i = i + 1
- End If
- Wend
- End If
- End With
- End If
- cboDSNList.ListIndex = 0
- End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д