*********************************
ODBC - Open DataBase Connectivity
*********************************
Basic Steps
Connecting to the SQL Server DataBase for retrieving information from tables
*************************************************************
The steps 1 - 3 are for connecting to the SQL Server Database
*************************************************************
1. Allocate ODBC Environment Handle
If SQLAllocEnv(glEnv) <> 0 Then
MsgBox "Unable to initialize ODBC API drivers!"
End
End If
______________________________________________________________
2. Allocate ODBC Database Handle
Dim iStatus As Integer
If SQLAllocConnect(glEnv, glDbc) <> 0 Then
MsgBox "Could not allocate memory for connection Handle!"
ODBCInit = False
' Free the Environment
iStatus = SQLFreeEnv(lEnv)
If iStatus = SQL_ERROR Then
MsgBox "Error Freeing Environment From ODBC Drivers"
End If
' Quit the Application
End
End If
______________________________________________________________
3. Connect using the sConnect string - SQLDriverConnect
Dim sResult As String
Dim iSize As Integer
Dim sConnect As String
sConnect = "DSN=" & gsDSN & ";UID=" & gsLoginID & ";PWD=" & gsPassword & ";APP=" & gsAppCode & ";DATABASE=" & gsDatabase
If SQLDriverConnect(glDbc, Screen.ActiveForm.hWnd, sConnect, Len(sConnect), sResult, Len(sResult), iSize, 0) <= 0 Then
MsgBox "Could not establish connection to ODBC driver!"
End If
______________________________________________________________
***************************************************
The steps 4 - 8 are for retrieving data from tables
***************************************************
4. Allocate ODBC Statement Handle
If SQLAllocStmt(glDbc, glStmt) <> 0 Then
MsgBox "Could not allocate memory for a statement handle!"
End If
______________________________________________________________
5. Execute ODBC Statement - SQLExecDirect
Dim lRet As Long, lErrNo As Long
Dim iLen As Integer
Dim sSQL