ibm-information-center/dist/eclipse/plugins/i5OS.ic.ddp_5.4.0.1/rbal1excon.htm

184 lines
11 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Explicit connection management" />
<meta name="abstract" content="The CONNECT statement is used to explicitly connect an application requester (AR) to an identified application server (AS). This SQL statement can be embedded within an application program or you can issue it using Interactive SQL." />
<meta name="description" content="The CONNECT statement is used to explicitly connect an application requester (AR) to an identified application server (AS). This SQL statement can be embedded within an application program or you can issue it using Interactive SQL." />
<meta name="DC.subject" content="explicit connection, SQL statement, CONNECT, explicit, password, in CONNECT statement, sending, security, in interactive SQL" />
<meta name="keywords" content="explicit connection, SQL statement, CONNECT, explicit, password, in CONNECT statement, sending, security, in interactive SQL" />
<meta name="DC.Relation" scheme="URI" content="rbal1cnct.htm" />
<meta name="DC.Relation" scheme="URI" content="rbal1ddmcnv.htm" />
<meta name="DC.Relation" scheme="URI" content="rbal1rdbdir.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rbal1excon" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Explicit connection management</title>
</head>
<body id="rbal1excon"><a name="rbal1excon"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Explicit connection management</h1>
<div><p>The CONNECT statement is used to explicitly connect an application
requester (AR) to an identified application server (AS). This SQL statement
can be embedded within an application program or you can issue it using Interactive
SQL.</p>
<div class="section"><p>The CONNECT statement is used with a TO or RESET clause. A CONNECT
statement with a TO clause allows you to specify connection to a particular
AS relational database. The CONNECT statement with a RESET clause specifies
connection to the local relational database.</p>
</div>
<div class="section"><p>When you issue (or the program issues) a CONNECT statement with
a TO or RESET clause, the AS identified must be described in the relational
database directory. The AR must also be in a connectable state for the CONNECT
statement to be successful.</p>
</div>
<div class="section"><p>The CONNECT statement has different effects depending on the connection
management method you use. For RUW connection management, the CONNECT statement
has the following effects: </p>
<ul><li>When a CONNECT statement with a TO or RESET clause is successful, the
following events take place: <ul><li>Any open cursors are closed, any prepared statements are discarded, and
any held resources are released from the previous AS if the application process
was placed in the connectable state through the use of COMMIT HOLD or ROLLBACK
HOLD SQL statement, or if the application process is running COMMIT(*NONE).</li>
<li>The application process is disconnected from its previous AS, if any,
and connected to the identified AS.</li>
<li>The name of the AS is placed in the Current Server special register.</li>
<li>Information that identifies the system module that returned the error
is placed in the SQLERRP field of the SQL communication area (SQLCA) or in
DB2_MODULE_DETECTING_ERROR of the SQL diagnostic area.</li>
</ul>
</li>
<li>If the CONNECT statement is unsuccessful for any reason, the application
remains in the connectable but unconnected state. An application in the connectable
but unconnected state can only run the CONNECT statement.</li>
<li>Consecutive CONNECT statements can be run successfully because CONNECT
does not remove the AR from the connectable state. A CONNECT to the AS to
which the AR is currently connected is run like any other CONNECT statement.</li>
<li>If running with commitment control, the CONNECT statement cannot run successfully
when it is preceded by any SQL statement other than CONNECT, SET CONNECTION,
COMMIT, ROLLBACK, DISCONNECT, or RELEASE. To avoid an error, perform a COMMIT
or ROLLBACK operation before a CONNECT statement is run. If running without
commitment control, the CONNECT statement is always allowed.</li>
</ul>
</div>
<div class="section"><p>For DUW connection management, the CONNECT statement has the following
effects: </p>
<ul><li>When a CONNECT statement with a TO or RESET clause is successful, the
following events take place: <ul><li>The name of the AS is placed in the Current Server special register.</li>
<li>Information that identifies the system module that returned the error
is placed in the SQLERRP field of the SQL communication area (SQLCA) or in
DB2_MODULE_DETECTING_ERROR of the SQL diagnostic area.</li>
<li id="rbal1excon__rbal1sql45"><a name="rbal1excon__rbal1sql45"><!-- --></a>Information on the type of connection is also placed into
the SQLCA and SQL diagnostic area. Encoded in these is the following information: <ul><li>Whether the application is in a connected or unconnected state can be
found in SQLERRD(5) in the SQLCA or in DB2_CONNECTION_STATE in the SQL diagnostic
area.</li>
<li>Whether a remote connection uses a protected or unprotected conversation
is found in SQLERRD(4) in the SQLCA or in DB2_CONNECTION_TYPE in the SQL diagnostic
area. </li>
<li>Whether the connection is always read-only, always capable of updates,
or whether the ability to update can change between each unit of work is found
in SQLERRD(4) in the SQLCA or in DB2_CONNECTION_STATUS in the SQL diagnostic
area.</li>
</ul>
<p>See the <a href="../sqlp/rbafykickoff.htm">SQL
programming</a> topic for more information about SQLERRD fields in the
SQLCA and about connection information in the SQL diagnostic area.</p>
</li>
</ul>
</li>
<li>If the CONNECT statement with a TO or RESET clause is unsuccessful because
the AR is not in the connectable state or the <span class="synph"><span class="var">server-name</span></span> is
not listed in the local relational database directory, the connection state
of the AR is unchanged.</li>
<li>A connection to a currently connected AS results in an error.</li>
<li>A connection without a TO or RESET clause can be used to obtain information
about the current connection. This includes the following information: <ul><li>Information that identifies the system module that returned the status
is placed in the SQLERRP field of the SQL communication area (SQLCA) or in
DB2_MODULE_DETECTING_ERROR of the SQL diagnostic area.</li>
<li>Other status information is described in the previous paragraphs
discussing the contents of SQLERRD(4) and SQLERRD(5) and the corresponding
information in the SQL diagnostic area.</li>
</ul>
</li>
</ul>
</div>
<div class="section"><p>It is a good practice for the first SQL statement run by an application
process to be the CONNECT statement. However, when you have CONNECT statements
embedded in your program you might want to dynamically change the AS name
if the program connects to more than one AS. If you are going to run the application
at multiple servers, you can specify the CONNECT statement with a host variable
as shown here, so that the program can be passed the relational database name.</p>
<pre>CONNECT TO : host-variable</pre>
</div>
<div class="section"><p>Without CONNECT statements, all you need to do when you change
the AS is to recompile the program with the new relational database name.</p>
</div>
<div class="section"><p>The following example shows two forms of the CONNECT statement
(<strong><span>1</span></strong> and <strong><span>2</span></strong>) in an application program: </p>
<pre>CRTSQL<em>xxx</em> PGM(SPIFFY/FIXTOTAL) COMMIT(*CHG) RDB(KC105)
PROC: FIXTOTAL;
EXEC SQL CONNECT TO KC105; <strong><span>1</span></strong>
EXEC SQL
SELECT * INTO :SERVICE
FROM REPAIRTOT;
EXEC SQL COMMIT;
EXEC SQL CONNECT TO MPLS03 USER :USERID USING :PW; <strong><span>2</span></strong>
EXEC SQL SELECT …
EXEC SQL COMMIT;
END FIXTOTAL;</pre>
</div>
<div class="section"><p>The example (<strong><span>2</span></strong>) shows the use of the USER/USING
form of the CONNECT statement. You must specify the user ID and password with
host variables when this form of the CONNECT statement is embedded in a program.
If you are using TCP/IP, a user ID and password can be extracted
from a security object at connect time if you have used the <span class="cmdname">Add Server
Authentication Entry (ADDSVRAUTE)</span> command with the appropriate parameters
to store them.</p>
</div>
<div class="section"><p>The following example shows both CONNECT statement forms in Interactive
SQL. Note that the password must be enclosed in single quotation marks.</p>
<pre class="screen">Type SQL statement, press Enter.
Current connection is to relational database (RDB) KC105.
CONNECT TO KC000_________________________________________________________
COMMIT___________________________________________________________________
===&gt; CONNECT TO MPLS03 USER JOE USING 'X47K'_____________________________
_________________________________________________________________________
_________________________________________________________________________
</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbal1cnct.htm" title="What makes a distributed relational database application distributed is its ability to connect to a relational database on another server.">Connect to a distributed relational database</a></div>
</div>
<div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="rbal1rdbdir.htm" title="The i5/OS licensed program uses the relational database directory to define the relational database names that can be accessed by applications running on an iSeries server, to specify if the connection uses Systems Network Architecture (SNA) or IP, and to associate these relational database names with their corresponding network parameters.">Use the relational database directory</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="rbal1ddmcnv.htm" title="The term connection in this topic collection refers to the concept of an SQL connection. An SQL connection lasts from the time an explicit or implicit SQL CONNECT is done until the logical SQL connection is terminated by such means as an SQL DISCONNECT, or a RELEASE followed by a COMMIT.">Control DDM conversations</a></div>
</div>
</div>
</body>
</html>