ODBCLINK/SE Reference Manual (36217-90410)

Using ODBCLink/SE With ODBC Applications ODBCLink/SE Reference Manual
ODBCLink/SE
50 ©M.B. Foster Associates Limited 1995-2000
4. 'Second allocate a connection handle
rc = SQLAllocConnect(henv, hdbc)
If rc <> SQL_SUCCESS Then
MsgBox ("SQLAllocConnect failed rc=" + Str(rc))
Call GetError
Call FreeEnv
Exit Function
End If
5. 'Third allocate the connection and pass in the Connection string
rc = SQLDriverConnect(hdbc, Form1.hWnd, sDSNConnect, Len(sDSNConnect),
outstr, 256, outlen, 3)
If rc <> SQL_SUCCESS Then
If rc = SQL_NO_DATA_FOUND Then
Exit Function 'User cancelled dialogue
End If
Call GetError
Call Freeconnect
Call FreeEnv
Exit Function
End If
6. 'After connecting, allocate a statement handle
rc = SQLAllocStmt(hdbc, hstmt)
If rc <> SQL_SUCCESS Then
Call GetError
Call Disconnect
Exit Function
End If
7. 'Now call an SQL query to select your data
rc = SQLExecDirect("Select * from member.membership")
If rc <> SQL_SUCCESS Then
Call GetError
MsgBox "Unable to connect to the Database Environment!", vbCritical
Call Disconnect
Exit Function
End If
End Function
8. Sub GetError()
Dim error_str As String * 256
Dim SQLState As String * 20
Dim outlen As Integer
Dim NativeError As Long
Dim msg As String