diff --git a/dlt/destinations/mssql/configuration.py b/dlt/destinations/mssql/configuration.py index 581da0f782..17f10ddff0 100644 --- a/dlt/destinations/mssql/configuration.py +++ b/dlt/destinations/mssql/configuration.py @@ -60,8 +60,7 @@ def _get_odbc_driver(self) -> str: def to_odbc_dsn(self) -> str: params = { "DRIVER": self.odbc_driver, - "SERVER": self.host, - "PORT": self.port, + "SERVER": f"{self.host},{self.port}", "DATABASE": self.database, "UID": self.username, "PWD": self.password, diff --git a/tests/load/mssql/test_mssql_credentials.py b/tests/load/mssql/test_mssql_credentials.py new file mode 100644 index 0000000000..9b57692bb2 --- /dev/null +++ b/tests/load/mssql/test_mssql_credentials.py @@ -0,0 +1,24 @@ +from dlt.common.configuration import resolve_configuration + +from dlt.destinations.mssql.configuration import MsSqlCredentials + + + +def test_to_odbc_dsn() -> None: + creds = resolve_configuration( + MsSqlCredentials("mssql://test_user:test_password@sql.example.com:12345/test_db?FOO=a&BAR=b") + ) + + dsn = creds.to_odbc_dsn() + + result = {k: v for k, v in (param.split('=') for param in dsn.split(";"))} + + assert result == { + 'DRIVER': 'ODBC Driver 18 for SQL Server', + 'SERVER': 'sql.example.com,12345', + 'DATABASE': 'test_db', + 'UID': 'test_user', + 'PWD': 'test_password', + 'FOO': 'a', + 'BAR': 'b' + }