Get Dsn And Driver (Api)

This code shows how to list the available DSN and Drivers installed on the
computer.
The program works by utilizing the SQLDataSources API of the ODBC32.DLL.

'[DECLARATION]
Declare Function SQLDataSources Lib "ODBC32.DLL" (Byval henv&, Byval
fDirection%, Byval szDSN$, Byval cbDSNMax%, pcbDSN%, Byval szDescription$,
Byval cbDescriptionMax%, pcbDescription%) As Integer
Declare Function SQLAllocEnv% Lib "ODBC32.DLL" (env&)
Const SQL_SUCCESS = 0
Const SQL_FETCH_NEXT = 1

Sub Click(Source As Button)
GetDSNsAndDrivers
End Sub

Sub GetDSNsAndDrivers()
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

On Error Resume Next

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)
sDRV = Left$(sDRVItem, iDRVLen)

If sDSN <> Space(iDSNLen) Then

Msgbox "DSN: " & sDSN & " DRIVER: " & sDRV

End If
Loop
End If
This was first published in November 2000
This Content Component encountered an error

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close