K
Keith G Hicks
Can anyone tell me why this fails? It works if I leave out the UID and PWD
lines but when those are in there it does nothing. It returns 0. I can
create the DSN manually in ODBC datasources using all the same parameters.
Option Compare Database
Option Explicit
Const ODBC_ADD_SYS_DSN = 4 'Add data source
Const ODBC_CONFIG_SYS_DSN = 5 'Configure (edit) data source
Const ODBC_REMOVE_SYS_DSN = 6 'Remove data source
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal _
hwndParent As Long, ByVal fRequest As Long, ByVal _
lpszDriver As String, ByVal lpszAttributes As String) As Long
Private Sub Command0_Click()
Call Build_SystemDSN
End Sub
Sub Build_SystemDSN()
Dim ret%, Driver$, Attributes$
Driver = "SQL Server" & Chr(0)
Attributes = "DSN=Keith Test 2" & Chr(0)
Attributes = Attributes & "DESCRIPTION=Keith Test for sqldb1" & Chr(0)
Attributes = Attributes & "SERVER=server" & Chr(0)
Attributes = Attributes & "DATABASE=sqldb1" & Chr(0)
Attributes = Attributes & "UID=sa" & Chr(0)
Attributes = Attributes & "PWD=abc123" & Chr(0)
ret = SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, Driver, Attributes)
'ret is equal to 1 on success and 0 if there is an error
If ret <> 1 Then
MsgBox "DSN Creation Failed"
End If
End Sub
Thanks,
Keith
lines but when those are in there it does nothing. It returns 0. I can
create the DSN manually in ODBC datasources using all the same parameters.
Option Compare Database
Option Explicit
Const ODBC_ADD_SYS_DSN = 4 'Add data source
Const ODBC_CONFIG_SYS_DSN = 5 'Configure (edit) data source
Const ODBC_REMOVE_SYS_DSN = 6 'Remove data source
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal _
hwndParent As Long, ByVal fRequest As Long, ByVal _
lpszDriver As String, ByVal lpszAttributes As String) As Long
Private Sub Command0_Click()
Call Build_SystemDSN
End Sub
Sub Build_SystemDSN()
Dim ret%, Driver$, Attributes$
Driver = "SQL Server" & Chr(0)
Attributes = "DSN=Keith Test 2" & Chr(0)
Attributes = Attributes & "DESCRIPTION=Keith Test for sqldb1" & Chr(0)
Attributes = Attributes & "SERVER=server" & Chr(0)
Attributes = Attributes & "DATABASE=sqldb1" & Chr(0)
Attributes = Attributes & "UID=sa" & Chr(0)
Attributes = Attributes & "PWD=abc123" & Chr(0)
ret = SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, Driver, Attributes)
'ret is equal to 1 on success and 0 if there is an error
If ret <> 1 Then
MsgBox "DSN Creation Failed"
End If
End Sub
Thanks,
Keith