HP MPE/iX 6.x Operating System manual Connection Examples, Connect Using SQL API

Models: MPE/iX 6.x Operating System

1 120
Download 120 pages 32.79 Kb
Page 59
Image 59

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 4.0-6.0. It is to be used as a basic guide line for creating a project to use SQLAPI. This examples assumes you have the necessary SQL Declare functions and Constants etc.

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 1995-2000

49

Page 59
Image 59
HP MPE/iX 6.x Operating System manual Connection Examples, Connect Using SQL API, Connect Using Sqlapi in VB