{"id":2384,"library":"apache-airflow-providers-microsoft-mssql","title":"Apache Airflow MSSQL Provider","description":"The Apache Airflow Microsoft MSSQL Provider enables seamless interaction with Microsoft SQL Server databases within Airflow DAGs. It provides hooks and operators for connecting to, querying, and managing data in MSSQL. This provider is part of the larger Apache Airflow ecosystem, currently at version 4.5.1, and receives updates aligned with Airflow's release cycle, as well as independent bug fixes and feature enhancements.","status":"active","version":"4.5.1","language":"en","source_language":"en","source_url":"https://github.com/apache/airflow/tree/main/airflow/providers/microsoft/mssql","tags":["Airflow","Database","Microsoft SQL Server","MSSQL","Provider","SQL"],"install":[{"cmd":"pip install apache-airflow-providers-microsoft-mssql","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core Airflow library required for running DAGs and tasks.","package":"apache-airflow>=2.2.0","optional":false},{"reason":"An alternative database driver for MSSQL connections, often used for Linux environments. Required if you use 'pymssql' as a connection driver.","package":"pymssql","optional":true},{"reason":"ODBC driver for MSSQL connections, common for Windows environments or when specific ODBC features are needed. Requires system-level ODBC drivers to be installed. Required if you use 'pyodbc' as a connection driver.","package":"pyodbc","optional":true}],"imports":[{"symbol":"MsSqlHook","correct":"from airflow.providers.microsoft.mssql.hooks.mssql import MsSqlHook"},{"symbol":"MsSqlOperator","correct":"from airflow.providers.microsoft.mssql.operators.mssql import MsSqlOperator"},{"symbol":"MsSqlToS3Operator","correct":"from airflow.providers.microsoft.mssql.transfers.mssql_to_s3 import MsSqlToS3Operator"}],"quickstart":{"code":"from __future__ import annotations\n\nimport pendulum\n\nfrom airflow.models.dag import DAG\nfrom airflow.providers.microsoft.mssql.operators.mssql import MsSqlOperator\n\n# Configure an Airflow Connection named 'mssql_default'\n# Host: your_mssql_host\n# Port: 1433 (default)\n# Schema: your_database_name\n# Login: your_username\n# Password: your_password\n# Extra: {\"driver\": \"ODBC Driver 17 for SQL Server\"} (if using pyodbc)\n\nwith DAG(\n    dag_id=\"mssql_quickstart_dag\",\n    start_date=pendulum.datetime(2023, 1, 1, tz=\"UTC\"),\n    schedule=None,\n    catchup=False,\n    tags=[\"mssql\", \"example\"],\n) as dag:\n    run_simple_query = MsSqlOperator(\n        task_id=\"run_select_statement\",\n        mssql_conn_id=\"mssql_default\",\n        sql=\"SELECT 1 as result;\",\n        autocommit=True,\n    )\n","lang":"python","description":"This quickstart demonstrates a simple Airflow DAG that uses the `MsSqlOperator` to connect to a Microsoft SQL Server database and execute a basic SQL query. Before running, ensure you have an Airflow connection named `mssql_default` configured with the appropriate host, credentials, and optional driver settings in your Airflow UI or via CLI."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer. If unable to upgrade Python, pin the provider version to `<4.0.0` (e.g., `apache-airflow-providers-microsoft-mssql<4.0.0`).","message":"The `apache-airflow-providers-microsoft-mssql` provider now requires Python 3.10 or higher. Users running Airflow on older Python versions (e.g., 3.8, 3.9) must upgrade their Python environment to use provider version 4.0.0 and above.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Choose your preferred driver: `pip install pymssql` OR `pip install pyodbc`. If using `pyodbc`, ensure the appropriate ODBC driver (e.g., 'ODBC Driver 17 for SQL Server') is installed and configured on the Airflow worker's operating system. Configure your Airflow connection's 'Extra' field to specify the driver, e.g., `{\"driver\": \"ODBC Driver 17 for SQL Server\"}`.","message":"This provider itself does not include the actual database drivers (`pymssql` or `pyodbc`). You must install one of these Python packages separately and ensure any necessary system-level ODBC drivers (for `pyodbc`) are also installed on your Airflow worker host.","severity":"gotcha","affected_versions":"All"},{"fix":"Carefully review MSSQL connection documentation for your specific SQL Server version and driver. Experiment with 'Extra' parameters like `{\"driver\": \"{ODBC Driver 17 for SQL Server}\", \"autocommit\": true, \"Encrypt\": \"yes\", \"TrustServerCertificate\": \"yes\"}`. Test the connection outside of Airflow using a simple Python script with your chosen driver to isolate connection issues.","message":"Connection string issues are common. Especially with `pyodbc`, specific driver names and connection parameters (e.g., trust server certificate) often need to be passed in the 'Extra' field of the Airflow connection to ensure successful negotiation with the SQL Server.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}