I'm learning Testcontainers with .NET and SQL Server. My fixture creates an MsSqlContainer from mcr.microsoft.com/mssql/server:2022-latest, sets the sa password with .WithPassword("Password1!"), starts the container, runs EF Core migrations, and uses the container's generated connection string for the DbContext. During startup, SQL Server logs repeated 18456 errors saying Login failed for user 'sa' because the password could not be evaluated. The container then finishes initializing, all tests pass, and no application-level authentication is configured. Is this a real configuration problem, or is it caused by SQL Server being contacted before startup has fully completed?
3 Answers
Check the complete startup logs and verify that the password is not being overridden elsewhere, such as through Docker environment variables or a separate connection string. SQL Server passwords must meet the required length and complexity rules; a weak or malformed value can produce this kind of error. With a valid password and the generated Testcontainers connection string, you generally do not need another Docker password setting.
The sa account is SQL Server’s built-in administrator login. The password needs to be configured consistently in the container and in the connection string. In your example, .WithPassword("Password1!") is the relevant container configuration, and using _container.GetConnectionString() should provide matching credentials. Also make sure the password satisfies SQL Server’s complexity rules.
Those messages look like startup noise rather than a final failure. SQL Server is still upgrading system databases and becoming ready when something tries to connect as sa. Testcontainers may perform readiness checks during that period, so an early login attempt can be logged even though the server eventually starts successfully. Since initialization completes and every test passes, the messages are probably transient.

That makes sense—the errors only appear while the container is starting, and the later log entries show SQL Server finishing its initialization without more login failures.