Hi, I want to use SQLDataSources to find out the driver of the database - whether it's oracle or sql server, etc. I found the code for VB6, but I couldn't make it work in .NET. Please point out what I am doing wrong!
Thanks!
Susie
____________________________
Here's the VB6 code that I tried to use.
Private Declare Ansi Function SQLDataSources Lib "odbc32.dll" _
(ByVal hEnv As Long, ByVal fDirection As Integer, _
ByVal szDSN As String, ByVal cbDSNMax As Integer, ByVal pcbDSN As Integer, _
ByVal szDescription As String, ByVal cbDescriptionMax As Integer, _
ByVal pcbDescription As Integer) As Integer
Private Declare Function SQLAllocEnv Lib "odbc32.dll" (ByVal phenv As Long) As Integer
Private Declare Function SQLFreeEnv Lib "odbc32.dll" (ByVal hEnv As Long) As Integer
Private Const SQL_SUCCESS As Long = 0
Private Const SQL_FETCH_NEXT As Long = 1
Private Const SQL_FETCH_FIRST_SYSTEM As Long = 32
Sub GetDSNsAndDrivers()
Dim i As Integer
Dim sDSNItem As String = New String(" ", 1024)
Dim sDRVItem As String = New String(" ", 1024)
Dim sDSN As String
Dim sDRV As String
Dim iDSNLen As Integer
Dim iDRVLen As Integer
Dim lHenv As Long
Dim strResult As String
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 = sDSNItem.Substring(0, iDSNLen)
sDRV = sDRVItem.Substring(0, iDRVLen)
If sDSN <> Space(iDSNLen) Then
strResult = strResult & sDSN & " (" & sDRV & ")" & vbNewLine
End If
Loop
End If
MsgBox(strResult)
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.