DBGate Application Settings
Table of Contents
- Introduction
- Configuration Sample
- Top-level Keys and Sections
- Common DBGate Settings
- Connection Settings
Introduction
DBGate reads its configuration from JSON files, specifically appsettings.json and appsettings.Production.json.
- The
appsettings.jsonfile contains settings for all environments. - The
appsettings.Production.jsonfile contains settings specific to theProductionenvironment.
The appsettings.json file can be empty, represented by {}.
DBGate also supports configuration through environment variables and command-line options.
For more details, see Configuration in ASP.NET Core.
Configuration Sample
Here’s a sample configuration file:
{
"AllowedHosts": "*",
"Kestrel": {
"EndPoints": {
"Http": {
"Url": "http://localhost:5003"
}
}
},
"Logging": {
"LogLevel": {
"Default": "Warning",
"System": "Information",
"Microsoft": "Information"
}
},
"DBGate": {
"Auth": "jwt",
"WebRoot": "wwwroot",
"ApiRoot": "api",
"AppRoot": "app",
"AuthRoot": "auth",
"HomeRoot": "home",
"EditRoots": {
"edit": "edit.htm"
},
"LoginRoots": {
"login": "login.htm"
},
"ApplicationPathBase": null,
"ConnectionSegment": 0,
"DefaultPort": 5003,
"DefaultLanguageFolder": "en-us",
"AccessTokenExpirationInMinutes": 10,
"RefreshTokenExpirationInMinutes": 20160,
"MaxPageSize": 1000,
"UppercaseNamesInLowercase": true,
"DefaultContainerName": "default",
"DisableMetadataCache": false,
"DisableEditPageCache": false,
"IncludeAnnotations": true,
"HideConfigurationObjects": true,
"HideEditProcedures": true,
"EnableCodeBrowser": true,
"BinaryAsHex": false,
"BigNumbersAsString": false,
"FunctionPrefixes": "xl_validation_list_, xl_parameter_values_",
"FunctionSuffixes": "_select",
"LanguageParameters": "data_language, DataLanguage",
"TraceSQL": true,
"StopEnabled": false
},
"DBGateW": {
"WebRoot": "wwwroot",
"IntegratedSecurityEnabled": false,
"StopEnabled": true
},
"ConnectionStrings": {
"mssql": {
"Title": "SQL Server",
"Offline": false,
"AllowDatabaseChange": true,
"AllowServerChange": true,
"ProviderName": "System.Data.SqlClient",
"ConnectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=master;User ID=user;Pwd=pass"
},
"pgsql": {
"Title": "PostgreSQL",
"Offline": false,
"AllowDatabaseChange": true,
"AllowServerChange": true,
"ProviderName": "Npgsql",
"ConnectionString": "Server=localhost;Password=pass;User ID=user;Database=postgres"
},
"mysql": {
"Title": "MySQL",
"Offline": false,
"AllowDatabaseChange": true,
"AllowServerChange": true,
"ProviderName": "MySqlConnector",
"ConnectionString": "Server=localhost;Password=pass;User ID=user;Database=mysql"
},
"mssql-023": {
"Offline": false,
"Home": "sample02.htm",
"QueryList": "",
"IncludeSchemas": "s02 xls",
"ExcludeSchemas": null,
"HideSchemas": "xls",
"HideConfigurationObjects": true,
"HideEditProcedures": true,
"OmitSchemasInNames": "s02",
"ProviderName": "System.Data.SqlClient",
"ConnectionString": "Data Source=mssql.savetodb.com;Initial Catalog=AzureDemo100;User ID=sample02_user3;Pwd=Usr_2011#_Xls4168"
},
"marketplace": {
"Title": "Marketplace",
"Offline": false,
"OmitSchemasInNames": "marketplace",
"ApiNameReplacements": {
"usp_buyer_": "",
"usp_seller_": ""
},
"ProviderName": "MySqlConnector",
"ConnectionString": "Server=localhost;Password=pass;User ID=user;Database=marketplace",
"SignIn": "marketplace.usp_sign_in",
"SignUp": "marketplace.usp_sign_up",
"SignInRoleField": "role",
"SignInMessageField": "message",
"AuthContextValues": {
"auth_account_id": 1
},
"AuthContextParams": "auth_user_id auth_seller_id",
"RoleUsers": {
"auth": {
"Username": "marketplace_auth",
"Password": "Usr_2011#_Xls4168"
},
"default": {
"QueryList": "marketplace.xl_buyer_views",
"Username": "marketplace_buyer",
"Password": "Usr_2011#_Xls4168"
},
"buyer": {
"QueryList": "marketplace.xl_buyer_views",
"Username": "marketplace_buyer",
"Password": "Usr_2011#_Xls4168"
},
"seller": {
"QueryList": "marketplace.xl_seller_views",
"Username": "marketplace_seller",
"Password": "Usr_2011#_Xls4168"
}
}
}
}
}
Top-level Keys and Sections
- AllowedHosts
- This optional value enables host filtering.
See details at Host filtering with ASP.NET Core Kestrel web server.
Use*to serve endpoints for all hosts. - Kestrel
- This optional section configures the Kestrel web server.
Use it to define specific endpoint SSL certificates.
See details at Kestrel web server implementation in ASP.NET Core. - Logging
- This optional section configures logging features.
See details at Logging Configuration. - DBGate
- This section contains DBGate settings.
- DBGateW
- This section overrides DBGate settings for the console version built for .NET Framework.
It can only contain theWebRoot,IntegratedSecurityEnabled, andStopEnabledsettings. - ConnectionStrings
- This dictionary defines connection names and related properties, including the required connection strings.
DBGate uses connection names to configure endpoints.
For example, the sample above defines endpoints like/api/mssql/,/api/pgsql/,/api/mysql/,/api/mssql-023/, and/api/marketplace/.
Common DBGate Settings
- Auth
- This value defines the authentication schema.
Possible values:jwtandbasic.
The default value isjwt, which also allows using basic authentication. - WebRoot
- This value defines the folder containing the website contents.
The default value iswwwroot. - ApiRoot
- This value defines the API root, such as
apiin the/api/mssql/endpoint.
The default value isapi. - AppRoot
- This value defines the console application management root, such as
appin the/app/stopURL.
Supported POST commands:stop,hide, andshow.
To enable commands, setStopEnabledto true. - AuthRoot
- This value defines the root for JWT operations, such as
authin the/auth/mssql/loginURL.
Supported POST commands:login,logout,refresh, andgetToken. - HomeRoot
- This value defines the root for home redirect endpoints, such as
homein the/home/mssql/endpoint.
DBGate redirects such URLs to home pages set with theHomevalue or to the service document if the page is not set.
The default value ishome. - EditRoots
- This section defines edit roots, such as
editin the/edit/mssql/endpoint, and the associated HTML pages.
For example, DBGate returns theedit.htmpage content for the/edit/mssql/endpoint.
The default root isedit, and the default page isedit.htm. - LoginRoots
- This section defines login roots, such as
loginin the/login/mssql/endpoint, and the associated HTML pages.
DBGate returns thelogin.htmpage content for the/login/mssql/endpoint.
These endpoints do not require initial authentication.
The default root islogin, and the default page islogin.htm. - ApplicationPathBase
- This value defines the application path base.
Usually, you do not need to change this value.
See details at UsePathBaseExtensions.UsePathBase. - ConnectionSegment
- This value defines the order of the API root and connection name segments.
By default, DBGate allows using endpoints like/api/mssql/and/mssql/api/.
You can set it to 2 to allow only endpoints with the connection in the second segment like/api/mssql/, or set it to 1 to allow only the connection in the first segment like/mssql/api/.
The default value is 0. - DefaultPort
- This value defines the default port used when service URLs are not specified in the configuration, environment variables, or command-line arguments.
The default value is 5003. - DefaultLanguageFolder
- This value defines the default language folder for finding files when no specific language folder is specified in the URL.
For example, DBGate will return pages from theen-ussubfolder.
The default value isen-us. - AccessTokenExpirationInMinutes
- This value defines the expiration time for access tokens in minutes.
The default value is 10 minutes. - RefreshTokenExpirationInMinutes
- This value defines the expiration time for refresh tokens in minutes.
The default value is 20160 minutes (14 days). - MaxPageSize
- This value defines the maximum number of records returned in a response.
- UppercaseNamesInLowercase
- This value enables converting uppercase object and column names to lowercase.
DBGate leaves mixed-case names unchanged.
The default value is true. - DefaultContainerName
- This value defines the name of the default entity container and its schema.
The default entity container can be omitted in the URLs.
For example, endpoints like/api/mssql/and/api/mssql/default/use the same model.
The default value isdefault. - DisableMetadataCache
- This value allows disabling the metadata model cache.
Developers can use it to load the model from a database every time during development.
Note that you can also use the URL system parameter$reloadMetadata=trueor pressCtrland click theReloadbutton instead.
The default value is false. - DisableEditPageCache
- This value allows disabling the edit page cache.
Developers can use it when developing edit pages.
The default value is false. - IncludeAnnotations
- This value enables metadata annotations.
The built-in DBGate client does not depend on this option.
The default value is true. - HideConfigurationObjects
- This value hides configuration objects like
xls.objects,xls.handlers, and other objects of the SaveToDB Framework.
TheDBGatesection contains the default value, which you may override in the connection settings.
The default value is true. - HideEditProcedures
- This value hides edit procedures like
usp_cashbook2_insert,usp_cashbook2_update, andusp_cashbook2_deleteof theusp_cashbook2procedure.
DBGate uses these procedures internally to support POST, PUT, and DELETE operations.
You may publish these procedures to call them via POST requests.
TheDBGatesection contains the default value, which you may override in the connection settings.
The default value is true. - EnableCodeBrowser
- This value enables retrieving object definitions using the
/$definitionURL segment.
A user must have theVIEW DEFINITIONpermission to access the definition.
The default value is false. - BinaryAsHex
- This value enables serializing binary data as hex strings by default, instead of base64.
You can also use the URL system parameter$binaryAsHex=true.
The default value is false. - BigNumbersAsString
- This value enables serializing large numbers that lose precision in JavaScript as strings.
You can also use the URL system parameter$bigNumbersAsString=true.
The default value is false. - FunctionPrefixes
- This comma-separated value defines prefixes of stored procedure names to assign the function type instead of the default action type.
For example, if DBGate cannot detect the select nature of thexl_list_usersprocedure, it assigns the action type.
You can set prefixes directly.
The example above contains prefixes used in SaveToDB and DBGate examples. - FunctionSuffixes
- This comma-separated value defines suffixes of stored procedure names to assign the function type instead of the default action type.
For example, if DBGate cannot detect the select nature of theusp_users_selectprocedure, it assigns the action type.
You can set suffixes directly.
The example above contains suffixes used in SaveToDB and DBGate examples. - LanguageParameters
- This comma-separated value defines language context parameter names.
DBGate does not publish these parameters in the model but passes the defined values to all procedures that have these parameters.
This feature is useful for multi-tenant applications.
The example above includes theauth_account_idparameter, which can be used in stored procedures to process data for account 1. - TraceSQL
- This value enables SQL command tracing.
The default value is false. - StopEnabled
- This value allows stopping, showing, or hiding the console application using the
/app/stop,/app/show, and/app/hidePOST requests.
You can use these commands when integrating DBGate into your desktop apps.
You can change the/approot using theAppRootsetting.
The default value is false. - IntegratedSecurityEnabled
- This value enables integrated security in the console version built with .NET Framework.
Typically, this version serves localhost only and runs under the current user account, making it safe to allow integrated security for database connections.
The default value is false.
Connection Settings
- ProviderName
- This required value defines the provider name.
- ConnectionString
- This required value defines the connection string.
Use a real username and password or theuserandpassplaceholders.
In the latter case, DBGate requires a username and password when a user connects to the endpoint and replaces placeholders with the actual values. - AllowDatabaseChange
- This value allows changing a connection database via the URL in the format
<connection>:<database>.
For example, a user can use the URL/edit/mssql:AzureDemo100/to connect to theAzureDemo100database.
The default value is true for themaster,postgres, andmysqldatabases, and false for others. - AllowServerChange
- This value allows changing a connection server and database via the URL in the format
<connection>:<server>[,<port>][,<database>].
For example, a user can use the URL/edit/mssql:mssql.savetodb.com,AzureDemo100/to connect to theAzureDemo100database at themssql.savetodb.comserver.
The default value is false. - AllowPortChange
- This value allows changing a connection port via the URL in the format
<connection>:<server>[,<port>][,<database>].
For example, a user can use the URL/edit/mssql:mssql.savetodb.com,1433,AzureDemo100/to connect to theAzureDemo100database at themssql.savetodb.comserver on port 1433.
The default value is false. - Title
- This value defines a connection title shown to end users.
The default value is the connection name. - Offline
- This value allows disabling the endpoint.
DBGate immediately returns an offline message without attempting to connect to the database.
The default value is false. - Home
- This value sets the homepage of the connection.
DBGate redirects to this homepage when a user clicks theHomebutton.
To open the default page, hold theCtrlkey while clicking theHomebutton.
You can specify the file name only and place language-specific pages in folders likeen-usandzh-hans. DBGate will return the page based on the user's language.
In the example above, the connectionmssql-023usessample02.htmas the homepage. - QueryList
- This value defines a view in the SaveToDB QueryList format to advertise view objects only in the service document.
Use this feature to configure the entity container and keep the service root clear.
The default value is null, which advertises all select-nature database objects available to the user. - IncludeSchemas
- This space-separated value defines an explicit list of schemas to include in the model.
If the value is empty, the model includes only the database for MySQL and all schemas except those specified in theExcludeSchemasvalue for other servers.
You may specify*to include all schemas for MySQL. - ExcludeSchemas
- This space-separated value defines a list of schemas to exclude from the model.
- HideSchemas
- This space-separated value defines a list of schemas whose objects will not be advertised in the service document.
- HideConfigurationObjects
- This value hides configuration objects like
xls.objects,xls.handlers, and other objects of the SaveToDB Framework.
This value overrides the default value defined in theDBGatesection. - HideEditProcedures
- This value hides edit procedures like
usp_cashbook2_insert,usp_cashbook2_update, andusp_cashbook2_deleteof theusp_cashbook2procedure.
DBGate uses these procedures internally to support POST, PUT, and DELETE operations.
You may publish these procedures to call them via POST requests.
This value overrides the default value defined in theDBGatesection. - OmitSchemasInNames
- This space-separated value defines a list of schemas to omit from service object names.
For example, database objects likes02.cashbookors02.usp_cashbookare published by default ass02_cashbookands02_usp_cashbook.
In the example above, the schemas02is omitted, so database objects are published ascashbookandusp_cashbook.
If the value is empty, DBGate omits the schema if a database contains a single schema that does not include thexlsschema.
To disable this feature, specify a dummy schema likenone. - ApiNameReplacements
- This section defines strings to replace in the generated object names.
In the example above, DBGate replacesusp_buyer_andusp_seller_with empty strings.
For instance, names likeusp_buyer_purchasesandusp_seller_ordersare published aspurchasesandorders. - SignIn
- This value defines a procedure for authenticating users.
DBGate executes this procedure using the credentials of theauthrole from theRoleUserssection.
The procedure must have at least two parameters for the username and password.
It may also include parameters defined in theAuthContextValuessection.
The procedure must return at least one field defined in theAuthContextParamsvalue, usually a user ID.
Additionally, it may return the role and message fields defined in theSignInRoleFieldandSignInMessageFieldvalues.
If the procedure returns an error, DBGate attempts to authenticate the user using the database login and password. - SignUp
- This value defines a procedure for signing up new users.
The features and requirements are the same as forSignIn. - SignInRoleField
- This value defines the name of the result field containing the signed user role.
DBGate uses this role value to load settings from theRoleUserssection.
The default value isrole. - SignInMessageField
- This value defines the name of the result field containing the error message.
If the value is not null, DBGate raises an exception and returns the message to the user.
The default value ismessage. - AuthContextValues
- This section defines context parameter names and values.
DBGate does not publish these parameters in the model but passes the defined values to all procedures that have these parameters.
This feature is useful for multi-tenant applications.
The example above includes theauth_account_idparameter, which can be used in stored procedures to process data for account 1. - AuthContextParams
- This value defines parameters populated from the
SignInandSignUpprocedures.
DBGate does not publish these parameters in the model but passes the values to all procedures that have these parameters.
Usually, this is an internal user ID.
However, you may define and return any number of parameters.
In the example above, the application has two parameters:auth_user_idandauth_seller_id, which procedures may use. - RoleUsers
- This section contains settings for user roles.
It must define at least two built-in roles:authanddefault.
DBGate uses theauthrole credentials to execute theSignInandSignUpprocedures.
DBGate uses thedefaultrole credentials to serve authenticated user requests when theSignInandSignUpprocedures do not return a role or the role is not found in theRoleUserssection.
Each role must have at least two values:UsernameandPassword.
Additionally, the role may include theQueryListvalue, which defines a view that selects objects to advertise in the service document.
The example above also contains two additional roles:buyerandseller, allowing for different models for each user role.