I would like to obtain some code to automatic set up an ODBC conection by calling the interface API of windows.
Printable View
I would like to obtain some code to automatic set up an ODBC conection by calling the interface API of windows.
Try this code. It will set up a user odbc driver for an sql database.
Dim rc as Long
'Allocate environment for the driver
rc = SQLAllocEnv(hwnd)
If rc <> 0 then
MsgBox "Unable to allocate environment."
End
End If
rc = SQLConfigDataSource(0, 1, "SQL Server", _
"DSN=" & Driver & Chr(0) & _
"Server=" & IPAddress & Chr(0) & _
"Database=" & Chr(0) & _
"UseProcForPrepare=Yes" & Chr(0) & _
"Description=" & Chr(0) & Chr(0))
Oops
Don't forget to put this in a module to declare
the dll.
public Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (byval HM as Integer, byval Rq as Integer, byval Driver as string, byval Connect as string) as Integer
You don't need to call SQLAllocConv in order to call SQLConfigDataSource.
If you call it, you should also call SQLFreeEnv, and, the return value is not a return code, but a HENV - an environment handle.
you can use the RegisterDatabase method of the DAO object model, or use the "ODBC Driver and Data Source Name functions" Typelib that comes with VB 6's APE (Application Performance Explorer)