This is documentation for the next version of Grafana documentation. For the latest stable release, go to the latest version.
Configure the Microsoft SQL Server data source
This document provides instructions for configuring the Microsoft SQL Server data source and explains available configuration options. For general information on adding and managing data sources, refer to Grafana data sources and Data source management.
Before you begin
Grafana comes with a built-in MSSQL data source plugin, eliminating the need to install a plugin.
You must have the
Organization administratorrole to configure the MSSQL data source. Organization administrators can also configure the data source via YAML with the Grafana provisioning system.Familiarize yourself with your MSSQL security configuration and gather any necessary security certificates and client keys.
Verify that data from MSSQL is being written to your Grafana instance.
Add the MSSQL data source
To add the MSSQL data source, complete the following steps:
- Click Connections in the left-side menu.
- Click Add new connection
- Type
Microsoft SQL Serverin the search bar. - Select Microsoft SQL Server under data source.
- Click Add new data source in the upper right.
Grafana takes you to the Settings tab, where you will set up your Microsoft SQL Server configuration.
Configure the data source in the UI
Following are configuration options for the Microsoft SQL Server data source.
Warning
Kerberos is not supported in Grafana Cloud.
Connection:
TLS/SSL Auth:
Encrypt - Determines whether or to which extent a secure SSL TCP/IP connection will be negotiated with the server.
Note
If you’re using an older version of Microsoft SQL Server like 2008 and 2008R2, you may need to disable encryption to be able to connect.
Authentication:
Additional settings:
Additional settings are optional settings you configure for more control over your data source. This includes connection limits, connection timeout, group-by time interval, and Secure Socks Proxy.
Connection limits:
Connection details:
Windows ADS Advanced Settings
Private data source connect - Only for Grafana Cloud users.
Private data source connect, or PDC, allows you to establish a private, secured connection between a Grafana Cloud instance, or stack, and data sources secured within a private network. Click the drop-down to locate the URL for PDC. For more information regarding Grafana PDC refer to Private data source connect (PDC) and Configure Grafana private data source connect (PDC) for instructions on setting up a PDC connection.
Click Manage private data source connect to open your PDC connection page and view your configuration details.
After configuring your MSSQL data source options, click Save & test at the bottom to test the connection. You should see a confirmation dialog box that says:
Database Connection OK
Azure Entra ID (formerly Azure AD) Authentication
The following Azure authentication methods are supported:
- Current User authentication
- App Registration
- Managed Identity
- Azure Entra Password
The Azure SQL Server that you are connecting to should support Azure Entra authentication to support adding the App Registration as a user in the database. For configuration details, refer to the Azure SQL documentation.
Current User authentication
This is the recommended authentication mechanism when working with SQL Server instances that are hosted in Azure. It allows users to be authenticated to and query the database using their own credentials rather than long-lived credentials.
This authentication method requires your Grafana instance to be configured with Azure Entra ID (formerly Active Directory) authentication for login. With Azure Entra ID login, this method can be used to forward the currently logged in user’s credentials to the data source. The users credentials will then be used when requesting data from the data source. For details on how to configure your Grafana instance using Azure Entra refer to the documentation.
Note
Additional configuration is required to ensure that the App Registration used to login a user via Azure provides an access token with the permissions required by the data source.
The App Registration must be configured to issue both Access Tokens and ID Tokens.
- In the Azure Portal, open the App Registration that requires configuration.
- Select Authentication in the side menu.
- Under Implicit grant and hybrid flows check both the Access tokens and ID tokens boxes.
- Save the changes to ensure the App Registration is updated.
The App Registration must also be configured with additional API Permissions to provide authenticated users with access to the APIs utilised by the data source.
- In the Azure Portal, open the App Registration that requires configuration.
- Select API Permissions in the side menu.
- Ensure the
openid,profile,offline_accesspermissions are present under the Microsoft Graph section. If not, they must be added.- Select Add a permission and choose the following permissions. They must be added individually. Refer to the Azure documentation for more information.
- Select APIs my organization uses > Search for Azure SQL and select it > Delegated permissions >
user_impersonation> Add permissionsAfter all permissions have been added, the Azure authentication section in Grafana must be updated. The
scopessection must be updated to include the.defaultscope to ensure that a token with access to all APIs declared on the App Registration is requested by Grafana. After updated the scopes value should equal:.default openid email profile.
This method of authentication doesn’t inherently support all backend functionality as a user’s credentials won’t be in scope. Affected functionality includes alerting, reporting, and recorded queries. Also, note that query and resource caching is disabled by default for data sources using current user authentication.
To enable current user authentication for Grafana:
Set the
user_identity_enabledflag in the[azure]section of the Grafana server configuration.[azure] user_identity_enabled = trueIn the SQL Server data source configuration, set Authentication to Azure AD Authentication and the Azure Authentication type to Current User.
App Registration
You must create an app registration and service principal in Azure Entra to authenticate the data source. For configuration details, refer to the Azure documentation for service principals.
After the app registration has been created, make note of the tenant ID, client ID, and client secret. Take the following steps to add the app registration as a SQL user:
- Connect to your Azure SQL database as a user with administrative permissions (the user used here must have the ability to read your Azure Entra directory e.g. by possessing the
Directory Readersrole). - Run
CREATE USER [$IDENTITY_NAME] FROM EXTERNAL PROVIDER;, substitutingIDENTITY_NAMEwith the app registration name. - Grant the created user the appropriate level of permissions for your use-case. It is recommended that users configured for data sources only have reader permissions.
After the appropriate permissions have been granted, configure the SQL Server data source to use the app registration:
- In the SQL Server data source configuration, set Authentication to Azure AD Authentication and the Azure Authentication type to App Registration.
- Set the Azure Cloud value to the correct value. If you are using the Azure public cloud this will be Azure.
- Set the Directory (tenant) ID, Application (client) ID, and Client Secret values to those for your app registration.
Managed Identity
Note
Managed Identity is available only in Azure Managed Grafana or Grafana OSS/Enterprise when deployed in Azure. It is not available in Grafana Cloud.
You can use managed identity to configure SQL Server in Grafana if you host Grafana in Azure (such as an App Service or with Azure Virtual Machines) and have managed identity enabled on your VM. This lets you securely authenticate data sources without manually configuring credentials via Azure AD App Registrations. For details on Azure managed identities, refer to the Azure documentation.
To enable managed identity for Grafana:
Set the
managed_identity_enabledflag in the[azure]section of the Grafana server configuration.[azure] managed_identity_enabled = trueIn the SQL Server data source configuration, set Authentication to Azure AD Authentication and the Azure Authentication type to Managed Identity.
This hides the directory ID, application ID, and client secret fields, and the data source uses managed identity to authenticate to SQL Server.
You can set the
managed_identity_client_idfield in the[azure]section of the Grafana server configuration to allow a user-assigned managed identity to be used instead of the default system-assigned identity.
Ensure that the managed identity used is added to your Azure SQL instance as a user.
Azure Entra Password
Warning
Azure Entra Password is not a recommended authentication mechanism as it requires configuration using a single users password. Consider an alternative authentication method such as current user authentication or app registration.
You can connect to an Azure SQL database using the username and password of a user that has permissions in the desired database. This also requires an app registration to be configured with access to the database.
To enable Azure Entra password for Grafana:
Set the
azure_entra_password_credentials_enabledflag in the[azure]section of the Grafana server configuration.[azure] azure_entra_password_credentials_enabled = trueIn the SQL Server data source configuration, set Authentication to Azure AD Authentication and the Azure Authentication type to Azure Entra Password.
Set the User ID value to the username of the user in the Azure SQL database.
Set the Application Client ID to the client ID of the app registration that has been added to the Azure SQL database
Set the Password value to the password of the user in the Azure SQL database.
Min time interval
The Min time interval setting defines a lower limit for the
$__interval and [$__interval_ms][add-template-variables-interval_ms] variables.
This value must be formatted as a number followed by a valid time identifier:
Grafana recommends setting this value to match your Microsoft SQL Server write frequency.
For example, use 1m if Microsoft SQL Server writes data every minute.
You can also override this setting in a dashboard panel under its data source options.
Database user permissions
When adding a data source, ensure the database user you specify has only SELECT permissions on the relevant database and tables. Grafana does not validate the safety of queries, which means they can include potentially harmful SQL statements, such as USE otherdb; or DROP TABLE user;, which could get executed. To minimize this risk, Grafana strongly recommends creating a dedicated MySQL user with restricted permissions.
CREATE USER grafanareader WITH PASSWORD 'password'
GRANT SELECT ON dbo.YourTable3 TO grafanareaderAlso, ensure that the user doesn’t have any unwanted privileges from the public role.
Diagnose connection issues
If you use older versions of Microsoft SQL Server, such as 2008 and 2008R2, you might need to disable encryption before you can connect the data source.
Grafana recommends that you use the latest available service pack for optimal compatibility.
Provision the data source
You can define and configure the data source in YAML files as part of the Grafana provisioning system. For more information about provisioning, and for available configuration options, refer to Provision Grafana.
Provisioning example
apiVersion: 1
datasources:
- name: MSSQL
type: mssql
url: localhost:1433
user: grafana
jsonData:
database: grafana
maxOpenConns: 100
maxIdleConns: 100
maxIdleConnsAuto: true
connMaxLifetime: 14400
connectionTimeout: 0
encrypt: 'false'
secureJsonData:
password: 'Password!'


