From b74d8f28efe5ee35064fd30d2ea0241bb5599878 Mon Sep 17 00:00:00 2001 From: David Zidar <381720+DavidZidar@users.noreply.github.com> Date: Wed, 12 May 2021 01:58:51 +0200 Subject: [PATCH] Fix MS SQL connection string examples (#17801) pyodbc parameters passed via a connection string to sqlalchemy should be passed as query string parameters and must be lower case. sqlalchemy includes the following note in their source code: Note that in order for the dialect to recognize these keywords (including the ``driver`` keyword above) they must be all lowercase. Multiple additional keyword arguments must be separated by an ampersand (``&``), not a semicolon:: https://github.com/sqlalchemy/sqlalchemy/blob/13d01a03c55890e19f5721405f6e5fb45d37cac4/lib/sqlalchemy/dialects/mssql/pyodbc.py#L56-L59 --- source/_integrations/recorder.markdown | 4 ++-- source/_integrations/sql.markdown | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/_integrations/recorder.markdown b/source/_integrations/recorder.markdown index 49dc1f0f059..97ce6591b59 100644 --- a/source/_integrations/recorder.markdown +++ b/source/_integrations/recorder.markdown @@ -241,7 +241,7 @@ The following database engines are tested when major changes are made to the rec | PostgreSQL | `postgresql://user:password@SERVER_IP/DB_NAME` | | PostgreSQL (Socket) | `postgresql://@/DB_NAME` | | PostgreSQL (Custom socket dir) | `postgresql://@/DB_NAME?host=/path/to/dir` | -| MS SQL Server | `mssql+pyodbc://username:password@SERVER_IP/DB_NAME?charset=utf8;DRIVER={DRIVER};Port=1433;` | +| MS SQL Server | `mssql+pyodbc://username:password@SERVER_IP:1433/DB_NAME?charset=utf8&driver=DRIVER` |
@@ -392,6 +392,6 @@ You will also need to install an ODBC Driver. Microsoft ODBC drivers are recomme
-If you are using Hass.io, FreeTDS is already installed for you. The db_url you need to use is `mssql+pyodbc://username:password@SERVER_IP/DB_NAME?charset=utf8mb4;DRIVER={FreeTDS};Port=1433;`. +If you are using Hass.io, FreeTDS is already installed for you. The db_url you need to use is `mssql+pyodbc://username:password@SERVER_IP:1433/DB_NAME?charset=utf8mb4&driver=FreeTDS`.
diff --git a/source/_integrations/sql.markdown b/source/_integrations/sql.markdown index 042ba435d4b..4b66572a94f 100644 --- a/source/_integrations/sql.markdown +++ b/source/_integrations/sql.markdown @@ -176,7 +176,7 @@ Use the same `db_url` as for the `recorder` integration. Change `DB_NAME` to the ```yaml sensor: - platform: sql - db_url: "mssql+pyodbc://username:password@SERVER_IP/DB_NAME?charset=utf8;DRIVER={FreeTDS};Port=1433;" + db_url: "mssql+pyodbc://username:password@SERVER_IP:1433/DB_NAME?charset=utf8&driver=FreeTDS" queries: - name: DB size query: "SELECT TOP 1 SUM(m.size) * 8 / 1024 as size FROM sys.master_files m INNER JOIN sys.databases d ON d.database_id=m.database_id WHERE d.name='DB_NAME';"