Chapter 26: Using Connection Management
This section explains Connection Manager guidelines.
You must be careful not to release a connection that has unprocessed command results associated with it. Any time you send a command using a cached connection, you must completely process the results of the command before releasing the connection for reuse. Failure to process all results will cause errors in the next component that uses the connection.
Never release a connection into a cache other than the one in which it was created. If you follow the coding conventions illustrated in the examples, this issue should not be a problem.
Do not release a connection twice—this can cause unexpected problems.
The connection’s server name, user name, and password are fixed when the cache is established. However, other connection properties can be changed dynamically when the connection is opened. For example:
Server-side connection options – database options, Client-Library ct_options calls, or equivalent ODBC JDBC calls all affect the server’s response to commands sent on the connection.
Database context – different users of a cached connection may use different databases. You can avoid problems by explicitly changing the database each time a cached connection is used.
Connection properties – connection properties affect client-side connection behavior.
Follow these guidelines to avoid problems with inconsistent connection state:
Set any options and properties that your code requires when you obtain a connection.
If your code may share a cache with other components, set changed properties and options back to the original values before releasing the connection. Or change your application configuration so that components that require different database and connection properties use different connection caches.
If your code is the only user of a cache, and no other components use the named cache, then you do not need to set options and properties back to the original values; however, you will have to reset the properties to the original values when you get the connection again.
|Copyright © 2005. Sybase Inc. All rights reserved.|