How to enable long connection

As described in long-running connections vs. short-lived connections, if your application uses features that require the same database connection in a native C/S app, these features may fail to work in installable cloud apps, in which different database connections will be selected from the pool for the features.

Take the temp table as an example, to illustrate the difference:

  • In the traditional client/server application, the temp table will not be destroyed until the DISCONNECT statement is executed, so after this temporary table is created, you can perform operations with this temp table at any area you like.

  • In the installable cloud apps, if the temp table is created in connection A, and operations in connection B try to access this temp table, then errors such as "table not found" will occur. Or the temp table created in connection A is destroyed when connection A is returned to the pool, then operations with this temp table will fail even though connection A is selected again from the pool.

You cannot get the expected result in the installable cloud app, because the temp table is only valid in the current database connection (which is a short-lived connection).

To eliminate this difference, you can use the LongConnection database parameter to enable the installable cloud app to persistently use the same database connection for a particular client. For example,

DBParm = Database='nvo2csharp', Provider='SQLNCLI11', LongConnection=1

LongConnection=1 enables the installable cloud app to have the same long-running connection as the PowerBuilder native C/S app.

Take the local temp table again as an example, LongConnection=1 makes the same database connection to be used during the duration of the user session, therefore, the local temp table will stay active all the time and the same temp table will be used during the user session.

Best practices

1) If long connection is enabled, you will have to increase the transaction timeout value (120 seconds by default) to have the same interval as the session timeout value (3600 seconds by default). This is to prevent transaction timeout during the session. Because if the transaction times out, then a new database connection will be created, which means the temp table is not the same one. For how to set transaction timeout values, refer to Configure the timeout settings.

2) Long connection is not the best option under the PowerServer architecture. It is recommended that you enable the long connection only for the necessary transaction. Other transactions still use the default short-lived connections.