connect is a method of the sdb.sql module for opening database sessions.
The database is in ONLINE operational state.
Syntax
connect (database_user, password, database_name , host = '' config = '')
Attribute |
Description |
---|---|
database_user |
Name of the database user |
password |
Password of the database user Note that the password is case-sensitive. |
database_name |
Database name |
host |
Name or IP address of the database computer |
config |
Connection options (see below) Format: keyword=value[&keyword=value]... |
Keyword |
Values |
Default Value |
Description |
---|---|---|---|
autocommit |
on | off |
off |
AUTOCOMMIT mode on: After each SQL statement, the transaction is ended with a COMMIT. off: You control the transaction using the commit method (SapDB_Session class) and the rollback method (SapDB_Session class). |
cachelimit |
<value in kB> |
Database default value |
The cache limit of the database session in KB |
component |
odbc | cpc |
cpc |
odbc: The database chooses the SQL variant that is valid for ODBC for processing. cpc: The database chooses the SQL variant that is valid for the C++ precompiler for processing. |
genericResults |
on | off |
off |
on: The sql method (SapDB_Session class), sqlX method (SapDB_Session class), and the execute method (SapDB_Prepared class) return an object of the SapDB_Result class (sdb.sql module) as a result. This can be useful, for example, for applications for which the SQL mode is unknown. off: The SQL results can differ according to the SQL statement that is executed. |
isolation |
0 | 1 | 2 | 3 | 10 | 15 | 20 | 30 |
Database default value |
Isolation level |
sqlmode |
internal | oracle |
internal |
SQL mode |
timeout |
0 | <value in seconds> |
Database default value |
Maximum inactivity time for a database session (in seconds) |
Result:
Successful execution: Object of the SapDB_Session class (sdb.sql module)
If an error occurs: Exception of the CommunicationError class (sdb.sql module)
Database user MONA with password RED connects to the DEMODB database on the local computer:
session=sdb.sql.connect ('MONA', 'RED', 'DEMODB')
Database user MONA with password RED connects to the DEMODB database on the computer PARMA:
session=sdb.sql.connect ('MONA', 'RED', 'DEMODB','PARMA')
Database user MONA with password RED connects to the DEMODB database on the local computer using the connection options SQL mode=ORACLE and command timeout = 60 seconds:
session=sdb.sql.connect ('MONA', 'RED', 'DEMODB','', 'sqlmode=oracle&timeout=60')
Example: Establishing and Closing the Connection to a Database