darylcollins@op2.co.uk
Apr 5th, 2000, 04:53 PM
trying to add a ODBC driver in the following code using VB6 but getting DSN failed:
Private Declare Function SQLConfigDataSource Lib "odbccp32.dll" (ByVal hwndParent As Long, ByVal fRequest As Integer, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long
Private Const ODBC_ADD_DSN = 1 ' Add a new data source.
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) existing data source.
Private Const ODBC_REMOVE_DSN = 3 ' Remove existing data source.
Private Const ODBC_ADD_SYS_DSN = 4 ' Add data source
Private Const ODBC_CONFIG_SYS_DSN = 5 ' Configure (edit) data source
Private Const ODBC_REMOVE_SYS_DSN = 6 ' Remove data source
Private Sub Command1_Click()
On Error Resume Next
If SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, _
"Microsoft Access Driver", _
"DSN=" & "Test" & Chr(0) & _
"DESCRIPTION=" & "Test" & Chr(0) & _
"SOURCETYPE=DBC" & Chr(0) & _
"SOURCEDB=" & "C:\Work\Op2\Database\Op2_desktop.mdb" & Chr(0) & _
"BACKGROUNDFETCH=YES" & Chr(0) & _
"NULL=YES" & Chr(0) & _
"DELETED=YES" & Chr(0) & _
"EXCLUSIVE=NO" & Chr(0) & Chr(0)) Then
MsgBox "DSN Created"
Else
MsgBox "DSN Failed"
End If
End Sub
Private Declare Function SQLConfigDataSource Lib "odbccp32.dll" (ByVal hwndParent As Long, ByVal fRequest As Integer, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long
Private Const ODBC_ADD_DSN = 1 ' Add a new data source.
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) existing data source.
Private Const ODBC_REMOVE_DSN = 3 ' Remove existing data source.
Private Const ODBC_ADD_SYS_DSN = 4 ' Add data source
Private Const ODBC_CONFIG_SYS_DSN = 5 ' Configure (edit) data source
Private Const ODBC_REMOVE_SYS_DSN = 6 ' Remove data source
Private Sub Command1_Click()
On Error Resume Next
If SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, _
"Microsoft Access Driver", _
"DSN=" & "Test" & Chr(0) & _
"DESCRIPTION=" & "Test" & Chr(0) & _
"SOURCETYPE=DBC" & Chr(0) & _
"SOURCEDB=" & "C:\Work\Op2\Database\Op2_desktop.mdb" & Chr(0) & _
"BACKGROUNDFETCH=YES" & Chr(0) & _
"NULL=YES" & Chr(0) & _
"DELETED=YES" & Chr(0) & _
"EXCLUSIVE=NO" & Chr(0) & Chr(0)) Then
MsgBox "DSN Created"
Else
MsgBox "DSN Failed"
End If
End Sub