Application Development |
Once the engine is initialized, you need to establish a connection before your application can access any data. There are three ways to connect your application to the database, depending on your specific development requirements, the application architecture, and your application's requirements. You can connect to a database:
(Refer to "Database Connect String" in JetNet/Oracle Tuxedo Guide for details on setting server properties and database connections using the JetNet manager. For Oracle Tuxedo, refer to "Initializing Servers" in JetNet/Oracle Tuxedo Guide).
In addition, the database engine must recognize your application users and grant them proper permissions, which can involve changes by your database administrator.
Connecting to the Database in the Screen Editor |
While you are designing your application, you need a direct connection to the database server if you are:
How to Make a Direct Connection to the Database from Within the Screen Editor
Choose FileCloseDatabase or in test mode, choose DatabaseDisconnect. Both options close direct connections on a specified engine. They do not close connections that have been established via the application server.
Programmatically Connecting to the Database |
A declared connection is a named structure describing a session about an engine. Two-tier applications contain the dbms commands to make direct connections to the database; in three-tier JetNet and Oracle Tuxedo applications, the dbms command is part of the application server initialization.
The syntax for DBMS DECLARE CONNECTION is:
DBMS [ WITH ENGINEengineName
] \
DECLAREconnectionName
CONNECTION WITH \
OPTION=argument
[, OPTION=argument
...]
The information provided about the engine includes:
USER
, PASSWORD
, DATABASE
, and SERVER
. If an option is not supported by the engine, the database driver reports an error—Bad arguments. To see a list of options for a specific engine, refer to "Database Drivers."
SELECT
cursor.
Once a connection is opened, the application can operate on the database tables.
A sample statement for JDB is:
At runtime, the application can execute the following command for each declared connection:
A connection is always associated with an initialized engine. Setting a connection as the default or current connection also sets the default or current engine. When using multiple connections, you should set a default connection.
Use the following command:
Use a WITH CONNECTION clause to specify the connection to use for a single statement. For example
Some database engines permit two or more simultaneous connections.
Refer to "Database Drivers" to see if this option is available for your engine.
Declare a named connection for each session on the engine. (The engine must support this feature.) For example:
This example declares two connections on the sybase engine and sets the default connection to be If you execute an additional connection statement for an engine supporting multiple connections, the support routine opens the additional connection and Panther keeps a count of the number of active connections for the engine.
If the engine does not support multiple connections or if the connection name is not unique, Panther returns the error Executing the following command:
If a two-tier application uses two or more database engines, a connection must be declared for each. You can then set a default connection. For example:
In the example, connections are declared on the engines sybase and oracle. Panther gets the values for In three-tier applications, connections to multiple database engines is usually handled by having a different application server for each database engine.
DBMS DECLARE vid_conn CONNECTION WITH DATABASE="videobiz"
How to Close Database Connections
DBMS CLOSE CONNECTION
connectionName
or
DBMS CLOSE_ALL_CONNECTIONS
Setting Default and Current Connections
How to Set a Default Connection
DBMS CONNECTION
connectionName
How to Override a Default Connection
DBMS WITH CONNECTION
oracon QUERY SELECT * FROM
customers Multiple Connections to a Single Engine
How to Make Multiple Connections to the Database
DBMS ENGINE sybase
DBMS DECLARE s1 CONNECTION WITH \
USER=:+uname
, PASSWORD=:+pword
, SERVER='birch'
DBMS DECLARE s2 CONNECTION WITH \
USER=:+uname
, PASSWORD=:+pword
, SERVER='maple'
DBMS CONNECTION s1s1
. Panther gets the values for USER
and PASSWORD
from the variables uname
and pword
at runtime.
DM_ALREADY_ON
.
How to Close All Connections on an Engine
DBMS [ WITH ENGINE
engineName
] CLOSE_ALL_CONNECTIONS Connecting to Multiple Engines
DBMS WITH ENGINE sybase DECLARE sybcon CONNECTION WITH \
USER=:+uname
, PASSWORD=:+pword
, SERVER='birch'
DBMS WITH ENGINE oracle DECLARE oracon CONNECTION WITH \
USER=:+uname
, PASSWORD=:+pword
DBMS CONNECTION sybcon
DBMS QUERY SELECT * FROM titles WHERE title_id = :+title_idUSER
and PASSWORD
from the variables uname and pword at runtime. The connection sybcon
is identified as the default engine. Therefore, Panther performs the SQL SELECT
on connection sybcon
and uses the support routine associated with the sybcon engine to execute the query.
Checking the Status of Connections |
Check whether a database connection is open using the library function dm_is_connection
. For example:
// This procedure finds out if the connection is
// open and if not, declares the connection.
proc check_connect
vars retcode
retcode=dm_is_connection("app_connect")
if retcode == 0
{
DBMS DECLARE app_connect CONNECTION WITH ...
}
return
Find out which database connection is assigned to a database cursor using the library function dm_cursor_connection
. For example:
// This procedure finds the connection for a cursor
// and makes it the default connection.
proc check_cursor
vars retcode
retcode=dm_cursor_connection("select_data")
DBMS CONNECTION :retcode
return
In order to interface with some database engine programs, you need information about the Panther database connection structure. Use the library function dm_get_db_conn_handle
to obtain this information.
Verifying Database Access |
Depending on your application architecture, you need to verify that users, processes, and services have database access and appropriate permissions on database tables or views.
For two-tier UNIX applications, verify that:
For two-tier UNIX web applications, verify that:
For three-tier JetNet and Oracle Tuxedo UNIX applications, verify that:
statement (part of the proserv configuration or JPL initialization) is configured for database access.
On Windows, you can install applications as a service. Windows assigns that service a user (owner) name; that user name must be configured for database access. Verify that the service has database access by:
Windows
Some database engines have special installation instructions. For example, Informix requires that you run For two-tier Windows applications, verify that:
setnet32
to add the service user and then run the demo login program to check that the user was added correctly.
For two-tier Windows web applications, verify that:
DBMS DECLARE CONNECTION statement (part of the proserv configuration or JPL initialization) is configured for database access.