Cannot connect to mssql localhost instance via Azure Data Studio. Get: 'login failed for user sa'.
In the same time I'm able to successfully connect via terminal: mssql -u sa -p myPassword
mssql is in docker with status up
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=myPassword" -p 1433:1433 --name sql1 -h sql1 -d mcr.microsoft.com/mssql/server:2019-latest
os: ubuntu 20.04
firewal is off
I'm sure that pwd is correct, as I can connect to mssql via terminal. Is it Azure settings? Or ubuntu?
Thank you in advance!
I was able to connect to sql instance via Azure Data Studio after change the password. I was using special characters (#, #, $) that might have caused the problem.
After altering password that doesnt iclude special characters it starts working!
Related
I'm able to run a SQL Server (for linux) instance in playwith docker
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password_01!" -p 1433:1433 --name sql1 --hostname ciccio -d microsoft/mssql-server-linux:2017-latest
and issue some commands from the terminal
docker exec -it sql1 /opt/mssql-tools/bin/sqlcmd -S ciccio -U sa -P Password_01!
However, I can't to connect to this instance from my local Management Studio.
Does anyone know how to do this? What check to see if the ports are open or the connection is reachable?
I've tried with the following address combinations:
http://ip172-18-0-43-bkarle1t0o8g00cjuvdg-1433.direct.labs.play-with-docker.com
http://ip172-18-0-43-bkarle1t0o8g00cjuvdg-1433.direct.labs.play-with-docker.com,1433
ip172-18-0-43-bkarle1t0o8g00cjuvdg-1433.direct.labs.play-with-docker.com
ip172-18-0-43-bkarle1t0o8g00cjuvdg-1433.direct.labs.play-with-docker.com,1433
the ip172-18-0-43-bkarle1t0o8g00cjuvdg-1433.direct.labs.play-with-docker.com are the urls provided from playwithdocker when the service is up and running
I can connect to SQL Server in a Docker container using...
Docker exec -it 93fc /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Password$$123
But I can't connect if I plug the same details into RazorSQL.
i.e. localhost with SA and Password$$123
What step am I missing?
This is the run command...
Docker run -e 'ACCEPT_EULA=Y' -e SA_PASSWORD=Password$$123 -p 1433:1433 -d microsoft/mssql-server-linux
This is a connection string I've tried from a test running in Visual Studio...
Data Source=localhost;Initial Catalog=master;User=sa;Password=Password$$123;
I think it can find the SQL Server but for some reason it can't login with SA.
Even this running from Windows doesn't work...
sqlcmd -S 192.168.10.79,1433 -U SA -P Password$$123
This problem goes away if I update the password using...
ALTER LOGIN SA WITH PASSWORD='Pa$$word123'
So I can connect to SQL Server inside the container using the initial password and then if I change the password I can connect externally.
How can the password determine if an external connection works?
If I enter env in the console, I get...
MSSQL_SA_PASSWORD=Password14961123
I presume that was auto generated.
I have a problem followng [this tutorial](https://hub.docker.com/r/microsoft/mssql-server-linux/
) where I try to connect to my docker hosted MSSQL via sqlcmd.
I executed the following in PowerShell from windows:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e \
'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it \
-d microsoft/mssql-server-linux:latest /bin/bash
Note: "-it" and "/bin/bash" is added due to docker will be stopped automatically if there is no any activity detected.
I ran docker container ls -a to verify it is running:
docker container Is -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92cfc504ab70 microsoft/mssql-server-linux:latest "/bin/bash" 27 minutes ago Up 27 minutes 0.0.0.0:1433->1433/tcp mssql
I ran telnet local-ip:1433 on my host, it is working fine.
Problem lies when I do the following:
docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U sa \
-P yourStrong(!)Password
Error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout
expired. 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..
I also tried to connect in using powershell via my host
Link:https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker
Command:
sqlcmd -S 192.168.0.110,1433 -U SA -P yourStrong(!)Password
Note: 192.168.0.110(got this from running ipconfig in host machine.)
Any help ?
I found out the problems after some trials and errors, and re-reading the documents. I should use double quotes for the arguments when I executed my command in PowerShell.
I was looking into the wrong direction. Initially I executed the command:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e \
'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d \
microsoft/mssql-server-linux:latest
Container stopped automatically by itself every time it starts.
Then, I did some googling and found:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e \
'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it -d \
microsoft/mssql-server-linux:latest /bin/bash
It seemed fine on the surface. It got executed successfully in PowerShell. It didn't stop automatically anymore.If I dig deeper using
docker container logs mssql
to see the log for mssql. No error given, just that I don't see a lots of info given, which led me to think that there were no problems in my command.
But the right way to run these commands is using double quotes.
Link: https://hub.docker.com/r/microsoft/mssql-server-linux/
IMPORTANT NOTE: If you are using PowerShell on Windows to run these commands use double quotes instead of single quotes.
E.g.
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStrong!Passw0rd" -p 1401:1433 --name sql1 -d microsoft/mssql-server-linux:2017-latest
I am also able to login using SSMS with:
Server name: Hostip,1401
Username: sa
Password:yourpassword
Try 127.0.0.1 or 0.0.0.0 instead of localhost
For example :
docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P 'yourStrong(!)Password'
docker run command syntax is the following:
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
When you execute the command:
docker run -e 'ACCEPT_EULA=Y' --name mssql -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it -d microsoft/mssql-server-linux:latest /bin/bash
/bin/bash in the end overrides CMD layer defined in the Dockerfile of microsoft/mssql-server-linux image.
So, just start a container without any additional command in the end:
$ docker run -e 'ACCEPT_EULA=Y' --name mssql -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -it -d microsoft/mssql-server-linux:latest
And now you are able to access a MSSQL:
$ docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'yourStrong(!)Password'
1>
I'm new to Docker and I also I had the same issue when I try to connect to the SQL Server container from my application(or sqlcmd app container from Microsoft) which is also running in another Docker container. It looks like each container gets its own subnet IP address, so 'localhost' would never work if you're trying to connect to the SQL from another container.
The command below will give you the full list of IP addresses in the bridge network. You can specify the IP directly in the connection string.
docker network inspect bridge
From your message, it looks the server is not configured to access remotely. Can you follow the way mentioned below to enable it?
Using SSMS (SQL Server Management studio):
In Object Explorer, right-click a server and select Properties.
Click the Connections node.
Under Remote server connections, select the Allow remote connections to this server check box.
Thanks,
Ananda Kumar J.
I am trying to run a docker container from the Microsoft SQL Server Express image (https://hub.docker.com/r/microsoft/mssql-server-windows-express/)
For example I've tried the following commands (I'll use the -d flag once I've got it working)
docker run -it -p 1433:1433 -e SA_PASSWORD=Mfp_4871nJUj_1-23H -e ACCEPT_EULA=Y --name to_delete_1 microsoft/mssql-server-windows-express powershell.exe
docker run -it -p 1433:1433 -e 'SA_PASSWORD=Mfp_4871nJUj_1-23H' -e 'ACCEPT_EULA=Y' --name to_delete_1 microsoft/mssql-server-windows-express powershell.exe
(not the real password - I've tried many passwords since one of the suggestions for fixing the error I see below is to ensure that the password meets Microsoft's password policy. However for all passwords I get the same error)
I've also tried lower case sa_password
However, each time I try to connect with the sa account from within the container using any of
sqlcmd -U sa -P Mfp_4871nJUj_1-23H
sqlcmd -S localhost -U sa -P Mfp_4871nJUj_1-23H
sqlcmd -S localhost\sqlexpress -U sa -P Mfp_4871nJUj_1-23H
sqlcmd -U sa
sqlcmd -S localhost -U sa
sqlcmd -S localhost\sqlexpress -U sa
(entering password for last 3)
I get
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login failed for user 'sa'..
Looking at the SQL Server logs it shows
2017-03-13 21:25:52.32 Logon Error: 18456, Severity: 14, State: 7.
2017-03-13 21:25:52.32 Logon Login failed for user 'sa'. Reason: An error occurred while evaluating the password. [CLIENT: 172.22.251.6]
The main advice is to ensure the password meets SQL Server's password criteria but I think all of the passwords I've tried do.
I run Docker on Windows 10 Enterprise (build 14393.693).
I have Docker for Windows Version 17.03.0-ce-win1 (10300).
What do I need to do to be able to connect to SQL Server from within the container using the microsoft/mssql-server-windows-express Docker imamge?
Thanks
I don't know if you ever found the answer to this question. I have not tried connecting to the database from within the container, but I have connected to it from SSMS from outside the container. The key for me was to specify the password in double quotes in the original command. The final command looked like this:
docker run -d -p 1433:1433 -e sa_password="useComplexPasswordHere" -e ACCEPT_EULA=Y microsoft/mssql-server-windows-express
I was then able to connect to it through SSMS. Get the IP address from the docker container using:
docker inspect
Then log in to the database through SSMS like this:
SSMS Login info
while trying to log in using this .. mssql -u sa -p mypassword .i get this error, Error: Failed to connect to localhost:1433 - connect ECONNREFUSED 127.0.0.1:1433
I have installed sql server on docker using this https://www.microsoft.com/en-us/sql-server/developer-get-started/java-mac tutorial and started it.
I am using mac os sierra. I have searched all over internet including stackoverflow for this but gotten no answer. The only answer i get is to enable tcp/ip using sql configuration manager, but mac os doesn't have a configuration manager so I can enable the tcp/ip. Kindly assist.
I finally found the solution .. the docker set the memory as 2GB while the MS SQL server requires 3.25GB... All i had to do was go to the Docker preferences and changed the memory to 4GB and it works :). I was using sql server on docker on Mac.
I'm using docker to set up containers and then sql-cli to access SQL server. This is how I resolved that error which I got after providing mssql -u sa -p mypassword.
What I didn't realize at the beginning was a too simple password provided before with setting up a docker container:
docker run -d --name Homer -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=myPassw0rd' -p 1433:1433 microsoft/mssql-server-linux
The Terminal doesn't say this and only after going to docker > Kitematic and checking the logs of the just created container I saw such a security warning. I deleted that container and created a container with a strong password.
Then I got the error after I've started a wrong container (so the connection failed because I was trying to provide the password for a different container). Since then, I prefer to use Kinematic to manage and access my containers. Before I type mssql -u sa -p mypassword in the Terminal and start to work, I just go to docker > Kinematic and Start my container.
In my case the container exited due to an insecure mssql password.
Try reading the container logs.
In my case, I just needed to start the container.
docker start {container_name}
In my case (I was following this tutorial https://database.guide/how-to-install-sql-server-on-a-mac/) the problem was the host address.
I was trying to connect to localhost and I got the ECONNREFUSED message but then I realized that I needed to use the local IP docker assigned to the container (it was something like 192.168.xxx.xxx), so:
mssql -s 192.168..... -o 1433 -u sa -p 'mypassword'
finally worded.
I had the same, in my case I notice that the problem was the PORT, so:
1)Check if the container is running with
docker start "container_name"
2)Then, get the correct PORT with:
docker ps
3) Run it
mssql -s "PORT" -o 1433 -u sa -p "pwd"
I'm adding this answer to complement Krzysztof Tomasz's answer.
I was following this guide: How to Install SQL Server on a Mac
Everything was going well but at the time of connecting to the container with this command:
mssql -u sa -p mypass1
I got:
Error: Failed to connect to localhost:1433 - connect ECONNREFUSED
127.0.0.1:1433
Then I opened Docker app, clicked the container and in the Logs menu I could see the following:
2020-02-05 16:26:45.71 spid20s ERROR: Unable to set system
administrator password: Password validation failed. The password does
not meet SQL Server password policy requirements because it is too
short. The password must be at least 8 characters..
The password I set had only 7 chars. :o)
Now this makes sense.
This is also documented # Microsoft doc here:
Quickstart: Run SQL Server container images with Docker
Solved this problem by removing the container and launching it again...
As I only had one container I ran the following command:
docker rm $(docker ps -a -q)
Then launched sql server image again with a stronger password:
docker run -d --name sql_server_demo -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=MyPass11' -p 1433:1433 microsoft/mssql-server-linux
I resolved this issue by updating the port from 1422 to 1433, I used Kitematic to implement this update.
I had the same, and it was a RAM issue, HOWEVER... 4GB didn't do it for me, for some reason in my case I needed 6, then it worked.
Make sure you have started the container in docker.
Command to start a container: docker start container "containerName"
and then try to connect mssql
I had same problem too, after study the logs with two commands:
docker ps -a
then
docker logs 99373f58f2ff
I understood that problem is related to the password dose not to meet SQL Server password policy! That's is.