Skip to main content

Connect to a Database

  • 2 minutes to read

Prerequisites

Prerequisites

  1. Register a data connection string provider.

    The Web Dashboard control does not expose connection strings from the configuration file (appsettings.json or Web.config) when used in Designer mode. You need to use a data connection string provider to avoid data leaks and pass connection parameters safely. You can use a predefined data connection string provider or implement a custom provider.

    For additional information, refer to the following help topics:

  2. Install a database provider if necessary.

For information on supported databases and required providers, refer to the following help topic: Supported Data Providers.

Select a Data Connection

The Choose a data connection page appears if you select Database on the start page. Select an existing connection from the list.

Web Dashboard - Choose a data connection

For information on how to register data connections in your application, refer to the following help topics:

Choose Queries

The next page allows you to create/edit a query or select a stored procedure. The image below displays a generated query in the SQL string editor.

Web Dashboard - Configure a query

Click Run Query Builder… to launch the Query Builder and choose the tables/columns visually.

Configure Query Parameters

If the SQL query contains query parameters, click Next to configure them.

Web Dashboard - Configure query parameters

You can use the following approaches to specify a parameter value:

  • Assign a static value

    Select a query parameter’s type from the Type drop-down list and specify a value based on the selected type.

  • Provide a dynamic parameter value

    Set the Type option to Expression and specify the Result Type. Click the Value option’s ellipsis button and construct an expression in the invoked Expression Editor.

Click Finish to create a new data source.

API

The database wizard pages are identified by the following API:

Page Name Page ID Class
Choose Connection (Database) SqlDataSourceWizardPageId.ChooseConnectionPage ChooseSqlConnectionPage
Choose Queries SqlDataSourceWizardPageId.ConfigureQueryPage ConfigureQueryPage
Configure Query Parameters SqlDataSourceWizardPageId.ConfigureParametersPage ConfigureQueryParametersPage
Choose Queries (a multi-query version) SqlDataSourceWizardPageId.MultiQueryConfigurePage MultiQueryConfigurePage
Configure Query Parameters (a multi-query version) SqlDataSourceWizardPageId.MultiQueryConfigureParametersPage MultiQueryConfigureParametersPage
See Also