SqlConnect Function (Long) | |
Establishes a connection to a data source.
Namespace:
XSharp.VFP
Assembly:
XSharp.VFP (in XSharp.VFP.dll) Version: 2.21
Syntax FUNCTION SqlConnect(
nStatementHandle AS LONG
) AS LONG
public static int SqlConnect(
int nStatementHandle
)
Request Example
View SourceParameters
- nStatementHandle
- Type: Long
This specifies that a new statement handle be created for the underlying shared connection that is represented
by nStatementHandle. The new statement handle uses the settings provided from nStatementHandle instead of using the default settings.
You cannot create a new statement handle for a connection that is not shared.
Return Value
Type:
Long
Numeric data type.
SqlConnect( ) returns a positive nonzero numeric value as the statement handle if you successfully connect to the data source.
SqlConnect( ) returns –1 if it cannot make the connection.
You should store this statement handle in a memory variable and use the variable in subsequent function calls that require a connection handle.
Remarks
The SqlConnect( ) and SqlStringConnect( ) functions return a numeric value as the statement handle rather than a connection handle.
You cannot obtain a connection handle directly. You can still set and get connection properties using the SqlSetProp( ) and SqlGetProp( )
functions by passing the statement handle for that connection and the string, "Shared", as arguments. All other SQL functions use a statement handle
instead of a connection handle.
If you issue a statement such as codeSqlConnect(cConnectionName, .T.)/code, and a shared connection is already open with the same name, then the settings
for that connection do not change to the settings stored for that connection in the database container (DBC). However, the new statement handle will use
the statement settings from the DBC.
You must disable the Open Database Connectivity (ODBC) login dialog box to support SQL pass through with Microsoft Transaction Server.
To disable the ODBC login dialog box, use the statement codeSqlSetProp(nStatementHandle, 'DispLogin', 3)/code, where cStatementHandle is the statement
handle returned by SqlConnect( ). You can also disable the ODBC login dialog box in the Connection Designer.
Examples Example 1
The following example assumes that an ODBC data source called MyFoxSQLNT exists and is available.
SqlConnect( ) returns a numeric value,
which is stored to a variable named codegnConnHandle/code.
If you successfully connect to the data source,
SqlConnect( ) returns a positive number, a dialog box appears, and
SqlDisconnect( ) is called
to disconnect from the data source.
If you cannot connect to the data source,
SqlConnect( ) returns a negative number and displays a message.
1STORE SqlConnect('MyFoxSQLNT', 'myUserID', 'myPassword') TO gnConnHandle
2IF gnConnHandle <= 0
3= MessageBox('Cannot make connection', 16, 'SQL Connect Error')
4ELSE
5= MessageBox('Connection made', 48, 'SQL Connect Message')
6= SqlDisconnect(gnHandle)
7ENDIF
Example 2
Each of the following examples create new shared connections. The Choose Data Source Dialog Box appears,
and
SqlConnect( ) creates the resulting connection as shared.
1SqlConnect(.T.)
2SqlConnect( myConnectionName, .T. )
3SqlConnect( myDataSourceName, myUserID, myPassword, .T. )
Example 3
Each of the following examples creates a new statement handle based on an existing shared connection.
1SqlConnect( nStatementHandleValue )
2SqlConnect( myConnectionName, .T. )
See Also