microsoft / mssql-docker

Official Microsoft repository for SQL Server in Docker resources
MIT License
1.69k stars 748 forks source link

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.) (Microsoft SQL Server, Error: 10054) #563

Open kunalverma94 opened 4 years ago

kunalverma94 commented 4 years ago

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=BB@@bb@123" -e "MSSQL_PID=Express" -p 1433:1433 mcr.microsoft.com/mssql/server:2017-latest-ubuntu

docker run --rm -it --name sql_server_thib -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=BB@@bb@123" -p 1433:1433 microsoft/mssql-server-linux

sqlcmd -S 127.0.0.1 -U sa -P BB@@bb@123

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'sa'..

kunalverma94 commented 4 years ago

They have changed thr port without documentation ....its 1434

docker run --rm -it --name sqlserver -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=1StrongPwd!!" -e "SA_PASSWORD=1StrongPwd!!" -p 1434:1434 microsoft/mssql-server-linux But wait theres more even after that you will be greated with

TITLE: Connect to Server

Cannot connect to 192.168.250.209,1434.


ADDITIONAL INFORMATION:

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.) (Microsoft SQL Server, Error: 10054)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=10054&LinkId=20476


An existing connection was forcibly closed by the remote host


BUTTONS:

OK

MrMelick-lab commented 4 years ago

Same here with docker image server:2017-CU18-ubuntu-16.04 and docker 2.203 stable version, the only solution is to reinstall docker when this error start to appear.

igorjacauna commented 4 years ago

I had to use Docker for Windows version 2.1.0.5 to solve this. And the problem never showed again.

MrMelick-lab commented 4 years ago

I've cleaned the mssql data folder and made a docker system prune and rebooted my machine and it started to work again.

croblesm commented 4 years ago

I was able to repro this issue, I think the problem is you are trying to connect to fast. SQL Server is probably still starting when you hit the SQLCmd session.

Without waiting:

[dba mastery] $  docker run --name sql_server_thib \
> -e "ACCEPT_EULA=Y" \
> -e "SA_PASSWORD=BB@@bb@123" -e "MSSQL_PID=Express" \
> -p 1433:1433 \
> -d mcr.microsoft.com/mssql/server:2017-latest-ubuntu
04eddb8956bfc021b716f8a13e88bd20dafc74cc88b4f5b5852a36c883a9495f

[dba mastery] $  sqlcmd -U sa -P 'BB@@bb@123'
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection because an error was encountered during handshakes before login. Common causes include client attempting to connect to an unsupported version of SQL Server, server too busy to accept new connections or a resource limitation (memory or maximum allowed connections) on the server..

5 seconds waiting:

[dba mastery] $  docker run --name sql_server_thib \
> -e "ACCEPT_EULA=Y" \
> -e "SA_PASSWORD=BB@@bb@123" -e "MSSQL_PID=Express" \
> -p 1433:1433 \
> -d mcr.microsoft.com/mssql/server:2017-latest-ubuntu
7f8484891adbd4b373447956ef5e927c5b4dea0b410a03bdd59b561f411b86d7

[dba mastery] $  sleep 5
[dba mastery] $  

[dba mastery] $  echo "Checking the container logs to make sure SQL is up"
[dba mastery] $  docker logs sql_server_thib -f
2020-03-10 06:20:33.74 spid21s     Service Broker manager has started.
2020-03-10 06:20:33.82 spid6s      Recovery is complete. This is an informational message only. No user action is required.
2020-03-10 06:20:34.17 spid10s     The default language (LCID 0) has been set for engine and full-text services.
^C
[dba mastery] $  sqlcmd -U sa -P 'BB@@bb@123'
1> exit

You can always use the docker logs command to make sure SQL Server completed the recovery successfully and then connect using SQLCMD.

Regards,

aimeos commented 4 years ago

We had the same problem on travis-ci. Sometimes it worked, often not:

sudo docker run --name=mssql-server -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=S3c0r3P4ss' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest && sudo docker cp sqlserver.sql mssql-server:sqlserver.sql && sudo docker exec -it mssql-server /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U SA -P 'S3c0r3P4ss' -i sqlserver.sql; fi
Unable to find image 'mcr.microsoft.com/mssql/server:2017-latest' locally
2017-latest: Pulling from mssql/server
Status: Downloaded newer image for mcr.microsoft.com/mssql/server:2017-latest
c489a696045690bef9da36c72c2c0d6ec905dccd075aed1374fe76a6d875363c
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'SA'..
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

Sleeping for 5 seconds didn't always help, because SQL Server sometimes requires more time for startup on virtualized servers with restricted resources. After we had increased sleeping for 10 seconds, it works now.

kunalverma94 commented 4 years ago

@dbamaster Thought I scarpped it out and switched to alternatives ..but for me i waited more than 5 minutes ...yet the problem perssted

croblesm commented 4 years ago

@dbamaster Thought I scarpped it out and switched to alternatives ..but for me i waited more than 5 minutes ...yet the problem perssted

I see, can you please copy the content of the SQL container log. In case your container name is still sql_server_thib:

docker logs sql_server_thib

Also, have you considered trying with a different SQL Server image? The latest image for Ubuntu 18.04 was released a week ago, maybe you want to give it a try: mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04

Regards,

superman-lopez commented 4 years ago

Same issue on 2017-latest. Luckily I am able to switch to 2019-latest which didn't have the problem.

GeoffreyFook commented 4 years ago

I got this error because I didn't meet password validation requirements. Make sure your password is at least 8 characters and contains a number and a special character.

Stupid mistake I know...

Jaxelr commented 3 years ago

@GeoffreyFook guess im in the stupid mistake boat, arrived here because of this error and it turns out that it was the password policy.

ChristopherJdL commented 3 years ago

I got this error because I didn't meet password validation requirements. Make sure your password is at least 8 characters and contains a number and a special character.

Stupid mistake I know...

I confirm that my issue was that. @microsoft has to make the error message more explicit.

ifaniqbal commented 3 years ago

In my opinion, the source of this issue is an inaccurate error message. I'm getting the same message like this, but my mistake was incorrect port.