
ODBCLink/SE Reference Manual | Using ODBCLink/SE With ODBC Applications |
Connection Examples
Connect Using SQL API
1.DECLARE YOUR VARIABLES FOR THE CONNECTION
2.CREATE YOUR CONNECTION STRING
3.ALLOCATE A ENVIROMENT HANDLE
4.ALLOCATE A CONNECTION HANDLE
5.CONNECT TO YOUR DSN WITH SQLDriverConnect
6.ALLOCATE A STATEMENT HANDLE
7.QUERY THE DATASOURCE USING SQLExecDirect
8. | CALL AN ERROR ROUTINE IF AN ERROR OCCURS See Sub GetError |
9.MAKE SURE YOU RELEASE ANY ENVIROMENT THAT YOU HAVE CREATED WHEN ERRORS OCCUR(or on exiting)
Connect Using SQLAPI in VB 4.0-6.0
The following example demonstrates how to use SQLAPI in VB
1.Global sDSNConnect As String 'Connection string
Global henv As Long | 'handle to the environment |
Global hdbc As Long | 'handle to the connection |
Global hstmt As Long | 'handle to the statement |
Global rc As Integer | 'Return code |
Dim outstr As String * 256
Dim outlen As Integer
Function DBConnect() As Integer
2.‘Add your connection string to be used
Example “DSN=YOUR DSN;UID=USERPWD=PASSWORD;”
sDSNConnect = “YOUR_DSN_STRING”
3.'First Allocate an Environment Handle rc = SQLAllocEnv(henv)
If rc <> SQL_SUCCESS Then
MsgBox ("SQLAllocEnv failed rc=" + Str(rc)) Exit Function
End If
ODBCLink/SE |
|
©M.B. Foster Associates Limited | 49 |