Skip to content

Commit

Permalink
fix: mssql database connect (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryuk-me authored Oct 8, 2024
1 parent e9444d1 commit ba9e850
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions dcs_core/integrations/databases/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,26 @@ 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"),
password=self.data_connection.get("password"),
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
# brew install unixodbc
# 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",
)
Expand Down

0 comments on commit ba9e850

Please sign in to comment.