Skip to content

SQLConnectionConnect - cSQLConnection

Establishes an embedded SQL connection that uses an existing connection from an earlier login or open

Type: Function
Return Data Type: Integer

Parameters

Parameter Type Description
sDrvrID String Driver Id
sConnectString String Connect String; must be an exact match, but can be case insensitive; can contain a connection id, e.g. "DFCONNID=MyConnectionID"

Syntax

Function SQLConnectionConnect String sDrvrID String sConnectString Returns Integer

Call Example

Get SQLConnectionConnect sDrvrID sConnectString to IntegerVariable

Description

SQLConnectionConnect establishes an embedded SQL connection that uses an existing connection from an earlier Login or Open. Existing connections are identified by their connect string (can be obtained with DF_DRIVER_SERVER_NAME attribute). If sConnectString exists in the list of existing connections, that connection will be used for embedded SQL.

Sample

Procedure TestSQLConnectionConnect
    String sConnectString sDriverId
    String[][] aResultSet
    Handle hdbc hstmt
    String  sSQLQuery

    Move "SERVER=(local);DATABASE=MssqlOrder190;Trusted_Connection=yes" to sConnectString
    Move "MSSQLDRV" to sDriverId

    // Login to a connection
    Login sConnectString "" "" sDriverId
    // Use the connection for embedded SQL
    Get SQLConnectionConnect of oSQLHandler sDriverId sConnectString to hdbc
    If (hdbc <> 0) Begin
        Get SQLOpen of hdbc to hstmt
        If (hstmt <> 0) Begin
            Move "Select * from SalesP" to sSQLQuery
            Send SQLExecDirect of hstmt sSQLQuery
            Get SQLFetchResultsetValues of hstmt to aResultset
            // Send ProcessResultSet aResultSet
            Send SQLClose of hStmt
        End
        Send SQLDisconnect of hDbc
    End
    Else Begin
        Showln (SFormat("SQLConnectionConnect could not connect to %1", sConnectString))
    End
End_Procedure

Return Value

Handle of an existing connection, if it exists; 0 if none exists.