Using CacheGroup property of DBParm

The DBParm CacheGroup property is added for specifying the cache group to be used by the installable cloud app. You can define multiple database connection scenarios in the cache groups, and then dynamically specify the CacheGroup value in DBParm, so that the deployed application will work in different database connection scenarios for different use cases.

The database caches you create in the project settings all belong to the "default" cache group. You can create new cache groups. There are two ways to do it:

  1. Add a new cache group in the compiled Web APIs > AppConfig folder > Applications.json file (or the solution > UserExtensions project > AppConfig folder > Applications.json file). You can create a new group by making a copy of the "default" group and then modify or add the cache in the new group. The cache group you created will be preserved when you build and deploy the PowerServer project (building and deploying the project will only update the "default" cache group).

  2. Add a new cache group dynamically in PowerScript by calling the AddGroup PowerServer Management APIs (refer to APIs for managing cache and cache group for more details).

The example below shows you how to add cache groups in the Applications.json file:

 "Connections": {
    "default": {
    ...
    },
    "cachegroup1": {
      "dbcache1": {
        "ConnectionType": "Odbc",
        "OdbcName": "sa-db1",
        "OdbcDriver": "SqlAnywhere",
        "UserID": "dba",
        "Password": "...",
        ...
      },
      "dbcache2": {
        "ConnectionType": "PostgreSql",
        "Database": "pgs-db1",
        "Host": "172.16.100.33",
        "Port": 5432,
        "UserID": "postgres",
        "Password": "...",
        ...
      },
      ...
    },
    "cachegroup2": {
      "dbcache1": {
        "ConnectionType": "Odbc",
        "OdbcName": "sa-db2",
        "OdbcDriver": "SqlAnywhere",
        "UserID": "dba",
        "Password": "...",
        ...
      },
      "dbcache2": {
        "ConnectionType": "PostgreSql",
        "Database": "pgs-db2",
        "Host": "172.16.100.89",
        "Port": 5432,
        "UserID": "postgres",
        "Password": "...",
        ...
      },
      ...
    },
    ...
  }

Then you can modify the application scripts to set the CacheGroup property:

//pass cachegroup from commandline
ls_cachegroup = commandlinearg
if len(ls_cachegroup) = 0 then
   ls_cachegroup = "default"
end if

//db connection info used by PowerBuilder native c/s app
SQLCA.DBMS = "SNC SQL Native Client(OLE DB)"
SQLCA.ServerName = "localhost"
SQLCA.AutoCommit = true

//if "DynamicConnection" is true in the cache, the LogID and LogPass property values will be used to log in to 
//the database server, instead of using the values specified in the cache.
SQLCA.LogPass = "mypass"
SQLCA.LogId = "mylog"

//cache and cachegroup used by PowerServer
SQLCA.DBParm = "Database='qa_datawindow',DelimitIdentifier=1,cachename='dbcache',cachegroup='"+ls_cachegroup+"'"
connect;

if sqlca.sqlcode <> 0 then
   messagebox("Database Error",sqlca.sqlerrtext)
   return
end if