By default, the cache, application settings (including run mode, timeout settings etc.), and transaction-to-cache mappings are stored in the static file (in the solution > UserExtensions project > AppConfig folder > Application.json or Applications.[DBConnectionProfile].json file).
You can also store these settings in a database and make APIs use the settings from the database instead of the file, by following steps below:
Step 1: Build and deploy the PowerServer project.
The database connection is stored to the PowerServer C# solution > UserExtensions project > AppConfig > Application.json or Applications.[DBConnectionProfile].json file by default.
Step 2: Open the PowerServer C# solution in SnapDevelop.
Step 3: Expand the solution > UserExtensions project > AppConfig, open the AppConfig.json file, and modify the "ConnectionStrings" section to point to the database that will store the database connections. The database can be an existing database that has or has no data.
Below is an example of connecting with an Oracle database:
"ConnectionStrings": { "AppConfig": "POOLING=True;ENLIST=true;USER ID=snaptest;DATA SOURCE=\"(DESCRIPTION=(ADDRESS=(HOST=192.15.6.211)(PORT=1521)(PROTOCOL=TCP))(CONNECT_DATA=(SERVICE_NAME=pdborcl)))\";CONNECTION TIMEOUT=15;STATEMENT CACHE SIZE=0;PROMOTABLE TRANSACTION=promotable;CONNECTION LIFETIME=0;METADATA POOLING=False;PERSIST SECURITY INFO=False;LOAD BALANCING=False;STATEMENT CACHE PURGE=False;PASSWORD=AppTest;VALIDATE CONNECTION=False;MIN POOL SIZE=1;MAX POOL SIZE=100;INCR POOL SIZE=5;HA EVENTS=False" }
Step 4: Open the AppConfigExtensions.cs file (which is in the same location as AppConfig.json), comment the following script so that it will no longer read the database connection from the file.
////Reads the static application configuration and db configuration //services.AddAppConfigFromFileSystem(context => //{ // // ASP.NET Core configuration, to get relevant configuration data (environment variables, commandline argument from different sources // // see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/ // context.Configuration = configuration; // // The folder of the configuration file. It shall be the path relative to the project folder, and can also be the absolute path or shared path // context.AppConfigDirectory = "AppConfig"; // // ASP.NET Core hosting environment, for reading the root directory of the application // // see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host#ihostenvironment // context.HostingEnvironment = hostingEnvironment; // //Uncomment the script below if you want to read configuration from self-defined program/file // //context.ProviderFactory = (applicationsFilePath, argumentConfigurationProvider) => // //{ // // // Self define the program/file that provides the configuration. It may be useful for some scenarios, such as, you need to refresh the db connection password periodically // // // It is recommended to inherit FileSystemConfigurationProvider and only customize some necessary logics // // return new YourCustomConfigurationProvider(applicationsFilePath, argumentConfigurationProvider); // //}; //});
Step 5: In the same file, go down and uncomment the script according to the type of the database so that it can successfully read the database connection from the database.
If you specify an Oracle database in step 3, then you will need to uncomment the script for Oracle here (must be the same database type).
// Uncomment the script below if you want to read configuration from Oracle services.AddAppConfigFromOracle(context => { // ASP.NET Core configuration, to get relevant configuration data (environment variables, commandline argument from different sources // see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/ context.Configuration = configuration; // The folder of the configuration file. It shall be the path relative to the project folder, and can also be the absolute path or shared path // This setting will send the configuration data in the configuration file to the database for initialization at the first startup of PowerServer context.AppConfigDirectory = "AppConfig"; // ASP.NET Core hosting environment, for reading the root directory of the application // see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host#ihostenvironment context.HostingEnvironment = hostingEnvironment; // The connection string to the db server that stores the configuration. Configure it in AppConfig/AppConfig.json context.ConnectionString = configuration.GetConnectionString("AppConfig"); });
Step 6: Double check Step 3, 4 & 5, and then click the Run button in SnapDevelop IDE.
When Web APIs runs, it creates three tables in the database: powerserver_applicationconfig, powerserver_connectionconfig, and powerserver_transactionconfig; and synchronizes the database caches, application settings, and transaction-to-cache mappings from the file to these tables.
Settings in the powerserver_applicationconfig table:
Settings in the powerserver_connectionconfig table:
Settings in the powerserver_transactionconfig table:
Note
The Web APIs will use the settings from the database tables instead of the file, which means the settings in the file will not take effect.
The settings will be synchronized from the file to the table for only one time when these tables are created. After that, if you want to change any setting, you should directly modify the setting in the table. If you make changes to the file, you will need to manually delete these three tables in the database and then run the Web APIs (Step 6) again, so that the tables will be created again and include the settings from the file.