Chalk supports Microsoft SQL Server and Azure SQL Database as a SQL source. You can configure the Microsoft SQL Server-specific options using the MSSQLSource init args, or configure the source through your dashboard, and reference the source in your code.

Prerequisites

For local development, you’ll need to install ODBC drivers:

  • macOS: brew install unixodbc
  • Linux (Ubuntu/Debian): sudo apt-get install unixodbc unixodbc-dev
  • Linux (RHEL/CentOS): sudo yum install unixODBC unixODBC-devel

Then install the Python package: pip install 'chalkpy[mssql]'

Production deployments on Chalk handle ODBC drivers automatically.

Adding Microsoft SQL Server

On the dashboard, you can plug in the configuration for your Microsoft SQL Server database:

Add Microsoft SQL Server

Add a Microsoft SQL Server integration. These parameters will also be available as environment variables.

Microsoft SQL Server
Environment

Learn more about Chalk's Microsoft SQL Server Integration

Authentication Methods

Chalk supports three authentication methods:

SQL Authentication - Traditional username and password authentication

Azure AD Managed Identity - When running in Azure (such as in AKS or Azure VMs), Chalk can automatically authenticate using Managed Identity. Simply omit authentication credentials when configuring your source.

Azure AD Service Principal - For authentication using an Azure AD application, provide client_id, client_secret, and tenant_id.

Integrations Setup

After configuring your Microsoft SQL Server integration in the dashboard, define your data sources in Python:

from chalk.sql import MSSQLSource

risk_source = MSSQLSource(name="risk")
marketing_source = MSSQLSource(name="marketing")

Then reference them in SQL file resolvers using the name parameter. For example, to query from the risk source:

-- type: online
-- resolves: User
-- source: risk
SELECT id, credit_score FROM users

And to query from the marketing source:

-- type: online
-- resolves: User
-- source: marketing
SELECT id, email, campaign_status FROM users
Named integrations inject environment variables with the standard names prefixed by the integration name. For example, if your integration is called risk, then the variable MSSQL_HOST will be injected as risk_MSSQL_HOST.