tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.38k stars 356 forks source link

mssql named instance port number #1566

Open adi1 opened 3 months ago

adi1 commented 3 months ago

Describe the bug When connecting to an mssql named instance, the connection string generated in tortoise.mssql.client.MSSQLClient still includes the port number. Named instances listen on dynamic ports, so the ,{port} should be left out, otherwise it tries to connect by default to port 1433 which fails.

To Reproduce Create an mssql connection with host containing a named instance, for example my_server\my_instance

Expected behavior It should work

Additional context One possible fix could be:

    if "\\" in host:
        # named instance, don't provide port
        server = host
    else:
        server = f"{host},{port}"
    self.dsn = f"DRIVER={driver};SERVER={server};UID={user};PWD={password};"