Click to See Complete Forum and Search --> : To Get The Driver name


sooruj
April 12th, 2001, 01:42 PM
My application is connecting to the database through DAO-ODBC.How can I know the type of the driver(Oracle or MSSQL) at run-time.
Is there any function wich gives me the driver type if I pass the ODBC datasource name as string?(In DAO)

Iouri
April 12th, 2001, 01:56 PM
here I found Johnny101 code to list all DSN and drivers

'Author John Pirkey


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

On Error Resume Next
lstDSN.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 = Left$(sDSNItem, iDSNLen)
sDRV = Left$(sDRVItem, iDRVLen)

If sDSN <> Space(iDSNLen) Then
lstDSN.AddItem sDSN
lstDrivers.AddItem sDRV '---optional - driver value returned
End If
Loop
End If
'remove the dups
If lstDSN.ListCount > 0 Then
With lstDrivers
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
lstDSN.ListIndex = 0
End Sub




Private Sub Form_Load()
GetDSNsAndDrivers
On Error Resume Next
lstDSN.ListIndex = 0
lstDrivers.ListIndex = 0

End Sub


Iouri Boutchkine
iouri@hotsheet.com