Cannot manage docker-based mysql server from Linux - sql-server

I installed an mssql server using docker container in an ubuntu EC2 as follows:
sudo docker run --name my_mssql -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<mypassword>" -p 1433:1433 -v /home/ubuntu/db:/var/opt/mssql -d microsoft/mssql-server-linux
sudo netstat -lpnt |grep 1433
shows 1433 is listening
I can login the mssql server using username=sa and password=mypassword using SQLPRO for MSSQL – a database manager, I can then create a database from that manager.
However, if I operate the mssql server from the EC2 in which the mssql server is installed, using the below command,
mysql -h <EC2 IP> -P 1433 -u sa -p
and then provide the password, it just stuck there and finally stop connecting with error message:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2
Why I cannot operate mssql server from the ubuntu EC2? How can I do that?

You DB server is MSSQL, and you are trying to connect with MSSQL using Mysql client, which will defiantly not work.
Can I use mysql to connect to SQL Server?
microsoft/mssql-server-linux
you can verify accessibility using
telnet EC2_IP 1433
or you can use sqlcmd or MSSQL client to connect with your DB container.

You're using SQL Server, not MySQL. You can't use another database's tools to connect to it.
You need to use SQL Server's command-line tools:
sqlcmd is the CLI query tool, similar to mysql
bcp is used for bulk import/export
You can also use Azure Data Studio (the unfortunate marketing name of what started as SQL Server Operations Studio). ADS can connect to SQL Server directly and PostgreSQL through an extension
It's a cross-platform editor/IDE similar to Visual Studio Code built for querying, visualizing results, managing databases and executing Python scripts and Jupiter Notebooks. It comes with server and database dashboards out of the box. There are several extensions for advanced monitoring and troubleshooting too.
It's also trivial to create new dashboards based on your own queries: Just copy the visualisations JSON definition into a settings file.

Related

Find connection string for DB in Rider/Azure Data Studio. SQL

I created server through docker with command:
docker run -d — name MySQLServer -e ‘ACCEPT_EULA=Y’ -e ‘SA_PASSWORD=your_password123’ -p 1433:1433 mcr.microsoft.com/azure-sql-edge
I'm working on an M1 Mac, and everything works fine. I created test DB and tables. Studio for visualization of my server I use Rider or Azure Data Studio. Both of them are friendly using but I can't get connection string for my DB from both of them. I need it for appSettings in my .NET project. How I can find it? In Visual Studio I found it in properties of DB. Here I don't see such option.
I am also using M1 Mac and SQL Edge coming from this tutorial.
In the ASP.NET WebApp the connection string looks something like this:
"ConnectionStrings": {
"Default": "Server=localhost; Database=<insert db name>; User Id=sa; Password=your_password123"
}

How to get a connection string to connect to cmdsql server created in Linux terminal?

I need to have a way to connect in Visual Studio Code to the server I created when configure the cmdsql in Linux. There is a way to do this?
I will explain a little better:
First I connect to the localhost server on Linux terminal using the next command. With this I can do querys directly on the terminal, to the databases hosted in server. I can create databases, tables, insert, update and more.
sqlcmd -S localhost -U SA -P 123456
I get the mssql extension for Visual Studio Code. There is a button '+ Add Connection' where I need to pass a connection string for connect to SQL Server.
What I need? I need a connection string to connect in Visual Studio to localhost server I created on Linux terminal.
Edit: Aditionally I will use this connection string to connect to SQL Server using pyodbc with Python based API I'm developing.

Connect to SQL Server Express running inside a container from SSMS

I am trying to connect to an instance of SQL Server Express running inside a container from SSMS running on my host machine.
The container was started as follows:
docker pull microsoft/mssql-server-windows-express
docker run -d -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=password" -p 1436:1433 --name mydb microsoft/mssql-server-windows-express
The container is running on the IP address that I got using
docker inspect --format '{{.NetworkSettings.Networks.nat.IPAddress}}' mydb
Now I am trying to connect to this instance, at the above IP address using SSMS, but get the following error:
I get the same error even if I change the case/position of the instance, e.g. 1.2.3.4,1436\SQLExpress, or 1.2.3.4\SQLExpress,1436.
What am I missing?
Possible duplicates:
Cannot connect to SQL Server express from SSMS
Connect to SQL Express with SSMS
But the answers didn't help me.
I have made sure that the container is up and running. I can ping to the IP address of the container.
The username and password are correct.
One thing I could be missing is that the SQL Server authentication is not enabled on the database instance in the container. I am not sure how to do that.
How can I connect to the SQL Server Express instance running inside a container from SSMS?
The original password I had used was weak (no I wasn't using password used in the question, but a different one which was still weak).
After starting a new container with a password which has combinations of uppercase, lowercase, characters, and numbers, I can now log into the database using following settings.

"The semaphore timeout period has expired" on connect to MS SQLServer inside WIndows Container

I have faced with very strange issue.
Host OS is Windows 10 Pro, installed Docker for Windows.
When I run microsoft/mssql-server-windows-developer container using simple command
docker run -d -p 1433:1433 -e sa_password=<SA_PASSWORD> -e ACCEPT_EULA=Y microsoft/mssql-server-windows-developer
I can connect to SQL Server via MS SQL Management Studio using server name=localhost. But I can't open Server Properties or open "Attach DB" wizard. There is the same error all the time "The semaphore timeout period has expired".
I can run container with attached DBs and I can execute sql inside MS SQL Management Studio. But when I run my Web Application - I get the same error "The semaphore timeout period has expired" on connect to DB.
Then I tried to connect to SQL Server using IP address which I get via docker container inspect - in my case it was 172.28.93.83. And everything worked as it should - I can manage with SQL Server, my Web Application connects to the DB, etc.
So, what is the issue there? I still want to use localhost to connect to server to have unified connection string in all developers environments.
When I tried to run Linux container - everything worked fine using localhost to connect to server.
I could be important - before I decided to use docker to work with MS SQL Server I had MS SQL Server installed and then uninstalled it. Maybe it made some changes in a routing or network which I have to remove...
I would appreciate any help
Try with increase timeout seconds in connection string.
I solved a similar incident changing the metric to the card generated by Docker.
I put 5000.
Luck.

Using SQL Server Management Studio to remote connect to docker container

Context: I am trying to build a development SQL Server that I can continue to learn SQL on and use Microsoft SQL Server Management Studio (SSMS) to access on a Windows PC.
So I have the AdventureWorks database sitting on a Docker Container for MS SQL Server 2017 running on a DigitalOcean Ubuntu 16.04 box. From my Mac I can remote SSH in to the server, access the container and query the database.
However I wish to use SSMS on my Windows PC and am unsure how I begin to connect to the remote box. In the picture below, there are no options to specify an SSH key or to even login in to the Ubuntu box, only to access the SQL server.
Is this even possible?
connect via SSMS using the public IP address, followed by comma separator and then the port (xxx.xx.xx.xxx,port)
You'll also need the sa credentials to make this work.
In your case, Server Name input will become Server IP, port#
No need of ssh, you just need to expose SQL Server service to the internet.
When Using SQL Server Management Studio to connect to the docker container on local machine, you can use localhost ip. In that case Server Name input will become 127.0.0.1,port#
Following instruction of this site solved it for me on Windows Containers:
https://www.sqlshack.com/sql-server-with-a-docker-container-on-windows-server-2016/
It was possible to connect to SQL Server instantly from SSMS.
Give it a try if this is also working on Linux containers with this command:
docker run --name mssqltrek-con1 -d -p 1433:1433 -e sa_password=My$eCurePwd123# -e ACCEPT_EULA=Y microsoft/mssql-server-windows-developer
After running this you can retrieve the correct ip with:
docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" mssqltrek-con1
In my case it was the Cisco VPN that was blocking the host to connect to container IP. I had to uncheck the "Cisco Any Connect Network Access Manager" as shown in the image below for it to work. It ensures that the VPN no longer manages the connection.
You can connect to SQL docker server
Using IP of Machine on which docker image is hosted,port
IP_Of_Machine,Port
Provide User - sa (default) and password.
you can also do it command>
docker exec -it <container_id|container_name> /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P <your_password>
This isn't exactly the same problem as the OP's but I created a sql docker container and then couldn't log in to it from SQL Server Management Studio. It turned out that the sa password I used wasn't secure enough. Once I deleted my container and recreated one with a more secure password it let me connect to it from SQL Server Management Studio. If you do not specify a strong enough password it still creates the container OK - you just can't log in to it!
Hopefully this will save someone some time.
I benefited from the answers on this page, however, i had to go through my own tweak. for some reason, in my case, it didnt accept localhost,1433 but it did accept 127.0.0.1,1433
In my case I was using docker-compose and was unable to connect. I fixed this by explicitly specifying the port in the docker compose file.
mysqldb:
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=SuperSecretPassword!23
image: registry/mysqlimage
I also faced same issue when I try to connect through SSMS, even I tried with localhost,1433 it doesn't help me out.
enter image description here
After some R&D I found the way to solve it
Open Kubernetes which will be installed as part of docker toolbox
(mine was win 10 home which will not support hyper-v)
click on sql container which will be in left side of app
copy the IP address which will be in right side of app
use IP address with port like XXX.XXX.XX.XX,1433 along with credentials in SSMS
enter image description here

Resources