{"record":{"id":"9941a717c2211010","repo":"pola-rs/polars","slug":"unable-to-identify-string-connection-as-valid-odbc","errorCode":null,"errorMessage":"unable to identify string connection as valid ODBC (no driver)","messagePattern":"unable to identify string connection as valid ODBC \\(no driver\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/database/functions.py","lineNumber":260,"sourceCode":"    ... )  # doctest: +SKIP\n\n    \"\"\"  # noqa: W505\n    if isinstance(connection, str):\n        # check for odbc connection string\n        if re.search(r\"\\bdriver\\s*=\\s*{[^}]+?}\", connection, re.IGNORECASE):\n            _ = import_optional(\n                module_name=\"arrow_odbc\",\n                err_prefix=\"use of ODBC connection string requires the\",\n                err_suffix=\"package\",\n            )\n            connection = ODBCCursorProxy(connection)\n        elif \"://\" in connection:\n            # otherwise looks like a mistaken call to read_database_uri\n            msg = \"string URI is invalid here; call `read_database_uri` instead\"\n            raise ValueError(msg)\n        else:\n            msg = \"unable to identify string connection as valid ODBC (no driver)\"\n            raise ValueError(msg)\n\n    # adbc_driver_manager must be >= 1.7.0 to support passing Python sequences into\n    # parameterised queries (via execute_options) without PyArrow installed\n    if (\n        execute_options is not None\n        and not _PYARROW_AVAILABLE\n        and type(connection).__module__.split(\".\", 1)[0].startswith(\"adbc\")\n    ):\n        adbc_version_no_pyarrow_required = \"1.7.0\"\n        adbc_driver_manager = import_optional(\"adbc_driver_manager\")\n        adbc_str_version = getattr(adbc_driver_manager, \"__version__\", \"0.0\")\n        if not parse_version(adbc_str_version) >= parse_version(\n            adbc_version_no_pyarrow_required\n        ):\n            msg = (\n                \"pyarrow is required for adbc-driver-manager < \"\n                f\"{adbc_version_no_pyarrow_required} when using parameterized queries (via \"\n                f\"`execute_options`), found {adbc_str_version}.\\nEither upgrade \"","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/database/functions.py#L242-L278","documentation":"When `read_database` receives a plain string that is not a URI (no \"://\"), it tries to interpret it as an ODBC connection string, which must contain a \"driver=\" component. Strings without a driver keyword cannot be identified and raise ValueError.","triggerScenarios":"Calling `read_database(query, \"some_string\")` where some_string lacks \"://\" and is not a valid ODBC connection string containing \"driver=...\" — e.g. a bare DSN name, a database name, or a truncated connection string.","commonSituations":"Passing a DSN name or database name as a string; mistyping a URI (missing \"://\"); assuming read_database accepts raw connection strings like a driver's own API.","solutions":["Include the driver in an ODBC-style string: `\"driver={PostgreSQL Unicode};server=...;uid=...\"`.","If it was meant to be a URI, fix the URI (add scheme) and call `read_database_uri`.","Pass an actual DBAPI connection object instead of a string."],"exampleFix":"// before\npl.read_database(\"SELECT * FROM t\", \"DSN=mydb\")  # raises: no driver=\n// after\npl.read_database(\"SELECT * FROM t\", \"driver={PostgreSQL Unicode};DSN=mydb\")\n# or: conn = pyodbc.connect(\"DSN=mydb\"); pl.read_database(q, conn)","handlingStrategy":"validation","validationCode":"if isinstance(connection, str) and \"://\" not in connection and \"driver=\" not in connection.lower():\n    raise ValueError(\"string must be a URI (use read_database_uri) or ODBC string containing 'driver=')","typeGuard":"def is_valid_odbc_string(s: str) -> bool:\n    return isinstance(s, str) and \"driver=\" in s.lower()","tryCatchPattern":"try:\n    df = pl.read_database(q, connection)\nexcept ValueError as e:\n    if \"valid ODBC\" in str(e):\n        conn = pyodbc.connect(f\"driver={{PostgreSQL Unicode}};{connection}\")\n        df = pl.read_database(q, conn)\n    else:\n        raise","preventionTips":["Always include driver= in ODBC-style connection strings","For DSN-based setups, open a pyodbc connection yourself and pass the object","Validate connection-string shape in config loading, before calling polars"],"tags":["polars","database","odbc","connection-string"],"backgroundTag":"invalid-argument-format","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}