Using CacheGroup property in 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 the new cache group in the PowerServer C# solution (in the ServerAPIs project > AppConfig > 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 every time when you build and deploy the PowerServer project (only the "default' cache group may be updated by deployment).

  2. Add the new cache group dynamically in PowerScript by calling the relevant PowerServer APIs (refer to Managing database connections using PowerServer APIs.)

The example below shows you how to add cache groups in the PowerServer C# solution:

 "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 use 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