SQL DISCONNECT DATASOURCE Statement |

< > Connection Statements Example Flow Chart Table of Contents

The SQL DISCONNECT DATASOURCE statement terminates a connection with a connected data source.

ConnectionHandle (input). This argument must specify a numeric integer value with at least six digits of precision. The value identifies the connection to be terminated. This value must have been returned by a successful SQL CONNECT DATASOURCE statement.

After an SQL DISCONNECT DATASOURCE statement is successfully executed, the connection handle value in ConnectionHandle is no longer valid for use in statements that use an input connection handle argument.

The application should set the data item that contains the connection handle value to zero to indicate that the connection handle is no longer connected. InstantSQL does not modify the data item used in the SQL DISCONNECT DATASOURCE statement, since it might not be the appropriate data item. For example, the statement might be contained in a common paragraph that is performed after moving the connection handle value that is to be disconnected to a temporary data item specified in the statement.

Any queries associated with the connection that have not already been dropped will be ended as if an SQL END QUERY statement, with the sql-Drop option, were executed for each such query prior to disconnecting from the data source. After a data source is disconnected, queries cannot be created for the data source unless another SQL CONNECT DATASOURCE statement is used to establish a new connection.

Attempting to disconnect from a data source when there is an active transaction on the connection will fail with an ODBC error with an SQL state of 25000, invalid transaction state. In this case, the connection is not closed and the transaction is still active. The transaction must be ended with an SQL COMMIT TRANSACTION or SQL ROLLBACK TRANSACTION statement before attempting to disconnect again. A transaction is not active until an SQL START TRANSACTION statement is executed and at least one SQL START QUERY statement is executed on the same connection.

SQL DISCONNECT DATASOURCE Statement Examples:

DISCONNECT-DB2.
MOVE DB2-ConnectionHandle TO sql-ConnectionHandle.

PERFORM ISQL-DISCONNECT-DATASOURCE.
MOVE ZERO TO DB2-ConnectionHandle.
DISCONNECT-SQLServer.
MOVE SQLServer-ConnectionHandle TO sql-ConnectionHandle.
PERFORM ISQL-DISCONNECT-DATASOURCE.
MOVE ZERO TO SQLServer-ConnectionHandle.

ISQL-DISCONNECT-DATASOURCE.
SQL DISCONNECT DATASOURCE
sql-ConnectionHandle.
MOVE ZERO TO sql-ConnectionHandle.

Copyright ©2000 Liant Software Corp. All rights reserved.