Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 472
  • Last Modified:

"ODBC DSN List in VB"


i want dsn (user dsn, file dsn, system dsn) list value in local pc in Visual Basic 6.0.
It is possible through ODBC Api then which Api is applicable for that.
Or any otherway it is possible to retrive list of dsn through vb.

1 Solution
Hi !

Just try this code!

this may not be the right one u want!

But u can get an idea with this!

i got this code from vbcode.com!

Private Declare Function SQLDataSources% Lib "ODBC32.DLL" (ByVal henv&, ByVal fdir%, ByVal szDSN$, ByVal cbDSNMax%, pcbDSN%, ByVal szDesc$, ByVal cbDescMax%, pcbDesc%)
Private Declare Function SQLAllocEnv% Lib "ODBC32.DLL" (env&)
Const SQL_SUCCESS As Long = 0
Const SQL_FETCH_NEXT As Long = 1

Public Sub GetDSNs(Box As ComboBox)
Dim i As Integer
Dim sDSNItem As String * 1024
Dim sDRVItem As String * 1024
Dim sDSN As String
Dim iDSNLen As Integer
Dim iDRVLen As Integer
Dim lHenv As Long     'handle to the environment

   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 = Left(sDSNItem, iDSNLen)
         If sDSN <> Space(iDSNLen) Then
            Box.AddItem sDSN
         End If
      Box.ListIndex = 0
   End If
End Sub

Private Sub Form_Load()
   Call GetDSNs(Combo1)
End Sub

Try using one of the template form in VB. Using Add Form - it will show you the template form available such as splash screen/about. There is such a template form for ODBC login

You can use the source code, which actually fills the combobox with the DSNs on your system

Do write back if it helps you

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now