testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

Bug: MSSQL (SqlServerContainer) ignores some parameters

Open meiswjn opened this issue 1 year ago • 2 comments

Describe the bug

When running the SqlServerContainer, in this example with the image mcr.microsoft.com/mssql/server:2022-CU12-ubuntu-22.04, some parameters have no effect on the actual database and lead to failures. It seems like they are just not respected.

To Reproduce

import sqlalchemy
from testcontainers.mssql import SqlServerContainer

def test_showcase_bug():
    with SqlServerContainer(image="mcr.microsoft.com/mssql/server:2022-CU12-ubuntu-22.04", username="dummy") as mssql:
        engine = sqlalchemy.create_engine(mssql.get_connection_url()) # this includes the username "dummy" now.
        print(mssql.get_connection_url())
        with engine.begin() as connection:
            result = connection.execute(sqlalchemy.text("select @@VERSION"))

It loads a while. When looking at the database logs, it prints:

2024-11-14 10:39:43.81 Logon       Error: 18456, Severity: 14, State: 5.
2024-11-14 10:39:43.81 Logon       Login failed for user 'dummy'. Reason: Could not find a login matching the name provided. [CLIENT: 172.17.0.3]

Same thing for other parameters, for example db_name.

Runtime environment

Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of testcontainers-python you are using? You can run the following commands to get the relevant information.

Windows 11 Python 3.11.9 testcontainers 4.8.2 sqlalchemy 2.0.36 pymssql 2.3.1

Thanks for your work!

meiswjn avatar Nov 14 '24 10:11 meiswjn

Hi,

I confirm the issue, using SqlServerContainer(image="mcr.microsoft.com/mssql/server:2022-CU12-ubuntu-22.04", username="SA", password="dumb_password").

Can't change the default username and password.

Thanks

Silicoman avatar Dec 14 '25 22:12 Silicoman

looks like there is no ability in the image to change the username, only the sa password can be changed.

if that is the case i can update the class to reflect this

https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-ver17

alexanderankin avatar Dec 15 '25 00:12 alexanderankin