Open kKen94 opened 4 years ago
Hello there,
This issue could be caused by your containers taking some time to get SQL Server started. Of course, It depends of your Docker daemon resources and configuration. But as an example in my case, I had the same problem experiencing variations with the SQL Server startup time from 10 to 20 seconds.
I would suggest using some kind of "wait" flag, for your application to connect after X amount of seconds. Just to make sure your SQL Server containers are up at the time the app is connecting.
Cheers,
Hi,
if you tell the truth it should be enough try with sqlOptions.EnableRetryOnFailure(10, TimeSpan.FromSeconds(5), null);
Anyway, I upgraded from sql-2017 to sql-2019
EnableRetryOnFailure
Cool!! That's pretty much what I do with Flyway to perform database migrations 😄
if you tell the truth it should be enough try with
sqlOptions.EnableRetryOnFailure(10, TimeSpan.FromSeconds(5), null);
I found that the this error (18456) was not included in the list of errors that get retried; I had to add it like this:
EnableRetryOnFailure(10, TimeSpan.FromSeconds(5), new List<int> { 18456 })
ETA: Sorry, to clarify: this is for the "Login failed" error
Can confirm here aswell.
I am using testcontainers in nodejs to start up a MSSQL container before tests. Testcontainers declared the container ready before it was, and therefore the server's connection failed even though I was puzzling how 3 seconds after I was able to login with sqlcmd
with the same credentials.
Just FYI for anyone using testcontainers for this purpose.
Solution is to use wait strategies
beforeAll(async () => {
container = await new GenericContainer('mcr.microsoft.com/mssql/server:2019-latest')
.withEnv('ACCEPT_EULA', 'Y')
.withEnv('MSSQL_SA_PASSWORD', 'solvency_SPIKE_234')
.withExposedPorts(1433)
.withWaitStrategy(Wait.forLogMessage('The tempdb database has 2 data file(s).'))
.start()
await connectionTest(container.getMappedPort(1433));
httpServer = await server();
});
Sometimes docker-compose connection results successful, sometimes get " A network-related or instance-specific error occurred while establishing a connection to SQL Server", sometimes "A connection was successfully established with the server, but then an error occurred during the pre-login handshake", sometimes ""Login failed for user ‘sa’"
I run docker-compose up until it works.
This my docker-compose:
And this one of net core Dockerfiles: