Difference between revisions of "SQLCONNECT()"

From Lianjapedia
Jump to: navigation, search
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
Connect to a data source
+
Connect to an ODBC data source
  
 
==Syntax==
 
==Syntax==
SQLCONNECT([<nStatementHandle>])
+
SQLCONNECT(<nStatementHandle>)
  
SQLCONNECT([<cConnectionName> | <cDataSourceName> [, <cUserID> [, <cPassword>]][, <lShared]])
+
SQLCONNECT(<cDataSourceName> [, <cUserID> [, <cPassword>]])
 
+
SQLCONNECT([<cServerDataSource>])
+
  
 
==See Also==
 
==See Also==
Line 13: Line 11:
  
 
==Description==
 
==Description==
The SQLCONNECT() function is used to connect to a data source and return a statement handle for use by other SQL functions.
+
The SQLCONNECT() function is used to connect to an ODBC data source and return a statement handle for use by other SQL functions.
  
If SQLCONNECT() is called without specifying any data source information, the Select a Gateway dialog is displayed allowing an existing gateway definition file (.gtw) to be selected.  Gateway files can be created in Recital Terminal Developer using the CREATE GATEWAY | MODIFY GATEWAY tool.
 
  
 
{| class="wikitable"
 
{| class="wikitable"
 
!Keywords||Description
 
!Keywords||Description
 
|-
 
|-
|nStatementHandle||The workarea in which a gateway data source is open and to which a new connection should be made.
+
|nStatementHandle||The workarea in which an ODBC data source is open and to which a new connection should be made.
 
|-
 
|-
 
|}
 
|}
Line 29: Line 26:
 
!Keywords||Description
 
!Keywords||Description
 
|-
 
|-
|cConnectionName||Existing gateway (.gtw) file
+
|cDataSourceName||ODBC data source name
|-
+
|cDataSourceName||ODBC data source name (ODBC supported platforms only)
+
 
|-
 
|-
 
|cUserID||Data source login user id
 
|cUserID||Data source login user id
 
|-
 
|-
 
|cPassword||Data source login password
 
|cPassword||Data source login password
|-
 
|lShared||False (.F.) Connection created is not shared (default)
 
True (.T.) Connection created is shared
 
|-
 
|}
 
 
Or
 
 
{| class="wikitable"
 
!Keywords||Description
 
|-
 
|cServerDataSource||ODBC, OLEDB or JDBC server side data source in the format:
 
odbc:odbc_data_source_name_on_server
 
oledb:oledb_connection_string_on_server
 
jdbc:dbc_driver_path_on_server;jdbc:Recital:args
 
 
|-
 
|-
 
|}
 
|}
Line 67: Line 47:
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
// SQLCONNECT() using the 'Select a Gateway' dialog
+
nStatHand = SQLCONNECT("awhr", "testuser", "password", .T.)
nStatHand=SQLCONNECT()
+
 
+
// SQLCONNECT(<nStatementHandle>) to an active gateway opened with SQLSTRINGCONNECT()
+
nStatHand=SQLSTRINGCONNECT("mysql@linux1:user1/pass1-database1.tcpip",.T.)
+
if nStatHand < 1
+
  messagebox([Could not connect])
+
else
+
  messagebox([Connected in workarea ]+str(nStatHand,3))
+
  nStatHand2=SQLCONNECT(nStatHand)
+
  if nStatHand2 < 1
+
    messagebox([Could not connect])
+
  else
+
    messagebox([Connected in workarea ]+str(nStatHand2,3))
+
  endif
+
endif
+
 
+
// SQLCONNECT() to an existing Gateway definition file
+
nStatHand = SQLCONNECT("gateway1.gtw",.T.)
+
 
+
// SQLCONNECT() to an ODBC data source
+
nStatHand = SQLCONNECT("SouthWind", "recital", "recital", .T.)
+
 
+
//SQLCONNECT() alternative syntax to an ODBC data source
+
nStatHand = SQLCONNECT("odbc:southwind")
+
 
+
//SQLCONNECT() to an OLEDB data source
+
nStatHand = SQLCONNECT ("oledb:Provider=vfpoledb.1;" + ;
+
"Data Source=C:Data;Collating Sequence=general")
+
 
</code>
 
</code>
  

Revision as of 11:04, 7 December 2012

Purpose

Connect to an ODBC data source

Syntax

SQLCONNECT(<nStatementHandle>)

SQLCONNECT(<cDataSourceName> [, <cUserID> [, <cPassword>]])

See Also

SQLCANCEL(), SQLCOLUMNS(), SQLCOMMIT(), SQLDISCONNECT(), SQLEXEC(), SQLGETPROP(), SQLMORERESULTS(), SQLPREPARE(), SQLROLLBACK(), SQLSETPROP(), SQLSTRINGCONNECT(), SQLTABLES(), SQLTRANSACTION()

Description

The SQLCONNECT() function is used to connect to an ODBC data source and return a statement handle for use by other SQL functions.


Keywords Description
nStatementHandle The workarea in which an ODBC data source is open and to which a new connection should be made.

Or

Keywords Description
cDataSourceName ODBC data source name
cUserID Data source login user id
cPassword Data source login password

Return values:

Return Value Description
>0 Statement handle to connection
–2 Connection creation error

Example

nStatHand = SQLCONNECT("awhr", "testuser", "password", .T.)