stromberg45
asked on
putting up DSN in vb6
g'day, i have read other people's questions about putting up DSN, and used some code in them. i find when i use the code, it's puts up the DSN that does not point to a database.
so it works, but just doesn't select the database. it's an access database. here is the code i use.
Public Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) _
As Long
'Constant Declaration
Private Const ODBC_ADD_DSN = 1 ' Add data source
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
Private Const ODBC_ADD_SYS_DSN = 4 ' add a new system data source
Private Const vbAPINull As Long = 0
Dim intRet As Long
Dim strDriver As String
Dim strAttributes As String
strDriver = "Microsoft Access Driver (*.mdb)"
strAttributes = "SERVER=SomeServer" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
strAttributes = strAttributes & "DSN=RM TEMP" & Chr$(0)
strAttributes = strAttributes & "DATABASE=" & App.Path & "RM.mdb" & Chr$(0)
intRet = SQLConfigDataSource(vbAPIN ull, ODBC_ADD_DSN, strDriver, strAttributes)
thanks.
so it works, but just doesn't select the database. it's an access database. here is the code i use.
Public Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) _
As Long
'Constant Declaration
Private Const ODBC_ADD_DSN = 1 ' Add data source
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
Private Const ODBC_ADD_SYS_DSN = 4 ' add a new system data source
Private Const vbAPINull As Long = 0
Dim intRet As Long
Dim strDriver As String
Dim strAttributes As String
strDriver = "Microsoft Access Driver (*.mdb)"
strAttributes = "SERVER=SomeServer" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
strAttributes = strAttributes & "DSN=RM TEMP" & Chr$(0)
strAttributes = strAttributes & "DATABASE=" & App.Path & "RM.mdb" & Chr$(0)
intRet = SQLConfigDataSource(vbAPIN
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thansk for that emoreau, worked perfectly !!
strAttributes = strAttributes & "DATABASE=" & App.Path & "\RM.mdb" & Chr$(0)