How to enable long connection

To maintain the same database connection in installable cloud apps (similar to a native C/S app), you can enable the LongConnection database parameter. This ensures that a particular client always use the same database connection throughout the session.

To enable it, set LongConnection to 1:

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

When LongConnection=1 is configured, the installable cloud app will maintain a long-running database connection, just like a PowerBuilder native C/S app.

Let's take the temp table as an example, to explain the behavior in the C/S app, and the behavior in the installable cloud app before and after enabling LongConnection:

  • In the traditional C/S app, 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 app (when LongConnection is disabled by default), if a temp table is created in connection A, and an operation later in connection B tries to access this temp table, errors such as "table not found" will occur. Or the temp table 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 picked again from the pool. Thus, temp tables cannot reliably persist across operations.

  • When LongConnection=1 is set, the same database connection is used consistently throughout the user session, therefore, the temp table remains active and accessible at all times during the session, just like in native C/S apps.

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.