{"id":10243,"library":"soda-core-sqlserver","title":"Soda Core SQL Server","description":"Soda Core SQL Server is a plugin for Soda Core, a data quality monitoring framework. It enables connecting to and scanning data quality checks against SQL Server databases. This library provides the necessary data source integration, allowing users to define checks on their SQL Server data using Soda's YAML-based configuration. Version 3.5.6 is current, and releases typically align with the active development cadence of the main `soda-core` library.","status":"active","version":"3.5.6","language":"en","source_language":"en","source_url":"https://github.com/sodadata/soda-core-sqlserver","tags":["data quality","observability","SQL Server","database","ETL","monitoring"],"install":[{"cmd":"pip install soda-core-sqlserver","lang":"bash","label":"Install SQL Server connector"}],"dependencies":[{"reason":"Core data quality framework for running scans and checks.","package":"soda-core"},{"reason":"Python ODBC driver for connecting to SQL Server databases, included as a direct dependency.","package":"pyodbc"}],"imports":[{"note":"`soda-core-sqlserver` is a plugin that auto-registers the 'sqlserver' data source type. There isn't a direct Python class import from this specific package that users commonly call. The primary programmatic interaction with Soda Core is through the `Scan` class from the `soda.scan` module, after the SQL Server data source is configured in YAML.","symbol":"SQL Server Data Source Type (via configuration)","correct":"This package enables `type: sqlserver` in your `configuration.yml`.\n\nFor programmatic scan execution: `from soda.scan import Scan`"}],"quickstart":{"code":"import os\nfrom soda.scan import Scan\n\n# Ensure environment variables are set for the quickstart to run\n# For local testing, replace os.environ.get with actual values or create a .env file\nhost = os.environ.get('SQLSERVER_HOST', 'localhost')\nport = os.environ.get('SQLSERVER_PORT', '1433')\ndatabase = os.environ.get('SQLSERVER_DATABASE', 'your_database')\nusername = os.environ.get('SQLSERVER_USERNAME', 'sa')\npassword = os.environ.get('SQLSERVER_PASSWORD', 'your_password')\n\n# Create a dummy configuration.yml and checks.yml for demonstration\n# In a real scenario, these files would be persisted.\nconfig_yaml_content = f\"\"\"\ndata_source:\n  type: sqlserver\n  host: \"{host}\"\n  port: \"{port}\"\n  database: \"{database}\"\n  username: \"{username}\"\n  password: \"{password}\"\n  # Add other connection options if needed, e.g., for trusted connections or specific drivers\n  # Example using system-installed ODBC Driver 17 for SQL Server on Linux/macOS:\n  # connection_string_user_defined_options: \"Driver={{ODBC Driver 17 for SQL Server}};Encrypt=no;TrustServerCertificate=yes;\"\n  # Example for Windows Trusted Connection (if your SQL Server supports it):\n  # connection_string_user_defined_options: \"Trusted_Connection=Yes;Encrypt=no;\"\n\"\"\"\n\nchecks_yaml_content = \"\"\"\nchecks for demo_table:\n  - row_count > 0\n  - missing_count(id) = 0\n\"\"\"\n\nconfig_path = 'configuration.yml'\nchecks_path = 'checks.yml'\n\nwith open(config_path, 'w') as f:\n    f.write(config_yaml_content)\nwith open(checks_path, 'w') as f:\n    f.write(checks_yaml_content)\n\nprint(\"Configuration and checks files created. Running Soda Scan...\")\n\nscan = Scan()\nscan.set_data_source_name('data_source') # Corresponds to the top-level key in configuration.yml\nscan.add_configuration_path(config_path)\nscan.add_checks_path(checks_path)\nscan.execute()\n\nif scan.has_failures():\n    print(\"Scan completed with failures.\")\nelse:\n    print(\"Scan completed successfully without failures.\")\n\n# Clean up generated files (optional, remove in persistent setups)\nos.remove(config_path)\nos.remove(checks_path)\n","lang":"python","description":"This quickstart demonstrates how to configure Soda Core to connect to a SQL Server database and run a simple data quality scan programmatically. It generates `configuration.yml` and `checks.yml` files, then executes a scan. Ensure your environment variables `SQLSERVER_HOST`, `SQLSERVER_DATABASE`, `SQLSERVER_USERNAME`, `SQLSERVER_PASSWORD` are set, and an ODBC driver for SQL Server is installed on your system. Replace placeholder values or environment variables with your actual SQL Server connection details."},"warnings":[{"fix":"Consult the official Soda Core documentation for the v3.x configuration format and migration guides. Key changes include how data sources are defined and how scan commands are structured.","message":"Soda Core v2.x and v3.x introduced significant changes in the configuration file format and CLI commands. `soda-core-sqlserver` versions are compatible with `soda-core` v3.x. Upgrading from v2.x requires updating your `configuration.yml` and `checks.yml` files.","severity":"breaking","affected_versions":"All versions >=3.0.0 (relative to Soda Core)"},{"fix":"Install the correct Microsoft ODBC Driver for SQL Server for your operating system. On Linux/macOS, use package managers like `apt` or `brew`. On Windows, download from Microsoft's website. Verify installation with `odbcinst -q -d` (Linux/macOS) or check ODBC Data Source Administrator (Windows).","message":"While `soda-core-sqlserver` installs `pyodbc`, you still need an appropriate ODBC driver for SQL Server installed on your operating system (e.g., 'ODBC Driver 17 for SQL Server'). Without it, `pyodbc` cannot connect to the database.","severity":"gotcha","affected_versions":"All"},{"fix":"Carefully review your `configuration.yml` connection parameters. Test your connection details using a simple `pyodbc` script or a database client tool first. Use `connection_string_user_defined_options` for advanced ODBC driver settings like specifying the exact driver name (e.g., `Driver={{ODBC Driver 17 for SQL Server}}`).","message":"SQL Server connection strings can be complex. Incorrect host, port, database, username, password, or driver options will lead to connection failures. Often, specific `connection_string_user_defined_options` are needed for trusted connections or custom setups (e.g., `Encrypt=no;TrustServerCertificate=yes;`).","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure `soda-core-sqlserver` is installed in your active Python environment: `pip install soda-core-sqlserver`. This command will also install `soda-core` as a dependency.","cause":"`soda-core` (or `soda-core-sqlserver`) is not installed or not in the Python path for the active environment.","error":"ModuleNotFoundError: No module named 'soda.scan'"},{"fix":"Install the appropriate Microsoft ODBC Driver for SQL Server for your operating system. For example, on Ubuntu: `sudo apt-get update && sudo apt-get install msodbcsql17 unixodbc-dev`. On macOS: `brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release && brew install msodbcsql17 mssql-tools`.","cause":"The required ODBC driver for SQL Server is not installed or not correctly configured on the system where Soda Core is running, even if `pyodbc` itself is installed.","error":"pyodbc.Error: ('01000', \"[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)\")"},{"fix":"Verify that the `data_source` key in your `configuration.yml` file exactly matches the name you provide to the `Scan` object or CLI command. E.g., if `configuration.yml` has `my_sql_server_ds:`, then use `scan.set_data_source_name('my_sql_server_ds')`.","cause":"The data source name specified in the `scan.set_data_source_name()` call (or CLI command) does not match the top-level key used to define the data source in `configuration.yml`.","error":"Scan failed: No data source was found for data_source: [your_data_source_name] in the configuration file."},{"fix":"Double-check all connection parameters in your `configuration.yml`. Ensure the SQL Server host is accessible from where Soda Core is running (check firewalls and network connectivity). Verify that the provided credentials are valid and have necessary permissions to access the database.","cause":"Authentication or connection details (host, port, database, username, password) are incorrect, or the SQL Server instance is unreachable/misconfigured.","error":"ERROR: [SODA] Could not connect to data source 'data_source'. Please check the connection details."}]}