Skip to content

Configuration Settings

Colin Mackay edited this page Feb 15, 2022 · 2 revisions

If you are setting up the SQL Configuration provider with information from existing providers such as app settings.json or a secret provider the following settings are available:

{
    "ConnectionStrings": {
        "ConfigDB": "*** Found in Secret Store ***"
    },
    "Stravaig": {
        "AppConfiguration": {
            "SchemaName": "Stravaig",
            "TableName": "AppConfiguration",
            "RefreshSeconds": 90,
            "ConnectionSring": "Server=localhost;Database=MyAppDB",
            "ConnectionStringName": "ConfigDB",
            "CommandTimeout": 10
        }
    }
}
  • SchemaName: The name of the schema in the database.
  • TableName: The name of the table that contains the configuration information. See Setup for how to create this table.
  • RefreshSeconds: The interval between polling the database table for changes.
  • ConnectionString: The connection string used to connect to the database.
  • ConnectionStringName: The name of the connection string in the "ConnectionStrings" section of the configuration.
  • CommandTimeout: The timeout (in seconds) for the command to run to get the information from the database.

Only one of "ConnectionString" or "ConnectionStringName" should appear. If both exist then the directly supplied connection string will take precedence over the named connection string.

The configuration builder

Host.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration(builder =>
    {
        builder.AddSqlServer(opts =>
        {
            // Will pull connection string, schema and table names from the 
            // configuration system up to this point from the default section.
            opts.FromExistingConfiguration();
        });
    })

If you want the information to come from a different section, then you can configure it like this:

builder.AddSqlServer(opts =>
{
    // Will pull connection string, schema and table names from the 
    // configuration system at the specified config section.
    opts.FromExistingConfiguration("MyApp:SqlConfiguration");
});
Clone this wiki locally