From 4e6b69894f9b790acbf4eeb035b034672af45f0b Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 8 Oct 2024 12:41:40 +0530 Subject: [PATCH] fix: mssql database connect --- dcs_core/integrations/databases/mssql.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dcs_core/integrations/databases/mssql.py b/dcs_core/integrations/databases/mssql.py index 9a5d57f..9202f07 100644 --- a/dcs_core/integrations/databases/mssql.py +++ b/dcs_core/integrations/databases/mssql.py @@ -30,6 +30,9 @@ def connect(self) -> Any: Connect to the data source """ try: + driver = ( + self.data_connection.get("driver") or "ODBC Driver 18 for SQL Server" + ) url = URL.create( drivername="mssql+pyodbc", username=self.data_connection.get("username"), @@ -37,6 +40,7 @@ def connect(self) -> Any: host=self.data_connection.get("host"), port=self.data_connection.get("port", 1433), database=self.data_connection.get("database"), + query={"driver": driver, "TrustServerCertificate": "YES"}, ) schema = self.data_connection.get("schema") or "dbo" # For osx have to install @@ -44,10 +48,8 @@ def connect(self) -> Any: # brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release # brew update # brew install msodbcsql mssql-tools - driver = self.data_connection.get("driver", "ODBC Driver 17 for SQL Server") - url_updated = f"{url}?driver={driver}" engine = create_engine( - url=url_updated, + url, connect_args={"options": f"-csearch_path={schema}"}, isolation_level="AUTOCOMMIT", )