Is it possible to inventory MSSQL-Linux running within Docker? - sql-server

Part of my job involves data collection to help size workloads that could be transferred to the cloud. An element of this is being able to enumerate SQL instances within a client's environment for insights such as "hey you have some out of support legacy SQL here that was supposed to be decommed years ago, what's the deal."
With the release of SQL Server 2017, I've just now created an instance of the SQL Server Enterprise 2017 on Linux container (using this image) that I'm running locally on Windows 10. I can connect to the instance via SSMS and SELECT ##VERSION to confirm it's legit, but my question is if it is possible to inventory the device and find the SQL instance without knowing that connection string.
Things I've tried:
-Running on Windows 10 so I believe this is supported via Hyper-V, when I try to go through the Hyper-V manager to connect to the VM Docker spun up, can't get any interface there (which I figured, since Docker emulates apps rather than full VMs)
-Tried to do a sqlcmd -L from the Win10 host device and don't see the instance (Don't have SQL installed on the Windows 10 device I'm running this from)
-I can find the docker image via a docker ps, then exec -it to bash, and use sqlcmd from there, but the sqlcmd -L isn't listed as an option within Linux.
-ipconfig from the host device shows the Docker IP address, but it wouldn't give me the port information so I would have to scan through all the ports which feels dirty.
I'm kind of at a loss at this point. If I didn't explicitly know a Docker container was running MSSQL-Linux, is there any way I could identify that from inventorying the host device? (sorry for the long post)

After banging my head on it for a bit I've found a painful workaround of:
connect to the container's bash using: docker exec -it <container_name> "bash"
then using ps aux | grep sql to list all of the sql processes. The MS image shows up as /opt/mssql/bin/sqlservr from local testing. Once SQL has been identified you can attempt to connect to it using the Docker ip from ipconfig and the port from docker ps
It's not elegant, but it should be possible to automate those steps for use across a set of unknown devices.
Leaving this open for a bit for any better alternatives.

Related

Cannot connect to SAP HANA Express DB using eclipse studio

I am new to SAP HANA database. I have successfully hosted the SAP HANA express database on cloud server. I have created a database and I am able to query it for the CLI.
However I have trouble connecting it from eclipse have spent two days on the same.
I am following https://developers.sap.com/india/tutorials/hxe-howto-eclipse.html tutorial.
Please Note :
I am able to connect to server using RDP and putty so the IP address is correct
I have started the database using command:
hdbsql -i 90 -d HXE -u SYSTEM -p SAPhxe123
why is eclipse taking port 39015 by default in last screenshot? is this the issue or can we change this.
Any help here would be much appreciated!
Remove the port and just keep HXE for the tenant.
39015 is the right one for the first tenant in an AWS or Azure VM (39017 is for Docker).
Try connecting to the system database first. If that works but the tenant doesn't, check this: https://developers.sap.com/tutorials/hxe-gcp-eclipse-tenant-connect.html
If that doesn't work: https://blogs.sap.com/2018/02/24/troubleshooting-connection-problems-for-hana-express/
Unless you explicitly closed port 22, ping should respond.
Also a reminder that HANA studio is part of a set of deprecated tools so if you are looking to learn native development, I would recommend going for XS advanced.
Could you please refer to following document: https://developers.sap.com/tutorials/mlb-hxe-tools-sql-eclipse.html
There the tenant database connection is created as follows
The host server (IP) is maintained in hosts file
Additionally the tenant db is only provided as HXE without port number
If you running the HANA server as a container.
Go in to the container "docker exec -it bash
HDB info
What is the port that you can connect to (If the Port is 39041 for example)
Rerun your container mapping your docker run command with -p:. That is (-p 3901:39015).
Essentially what is broken is that the port Eclipse HANA studio is trying to connect to is not mapped to the HANA port that is listening on.
You have to map the PORT that HANA is listening to Host PORT 39015.
If this is a cloud env you have to do the appropriate port forwarding.
Tested this and it works now.
For tenant database, I think it is enough to use HXE
Did you try to change the host name by adding the port information after IP address?
When your HXE instance was created on AWS, did you assigned it the default security group or did create one based on "Seller settings"?
This is really important because without this custom security group you won't be able to access your instance from the outside world.
Please refer to the following tutorial for more details: https://developers.sap.com/canada/tutorials/hxe-aws-setup.html

Connecting to SQL Server on host through Windows Server-based container

How do you connect to a SQL Server database on a host (or even in the cloud, as in off the local network) from a windows server-based container?
I've tried using
docker run --net="nat" ...
and
docker run --net="host" ...
to no avail.
Using -p does not seem relevant as I want to container to talk to the SQL Server database not running in a container.
I'm not sure how a custom network bridge can work here but I'm open to trying.

"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

Connect to SQL Server Developer from ASP.NET Core app running in Docker for Windows

I'm trying to connect to my SQL Server Developer edition on my local Windows 10 Pro machine from a docker image created using Visual Studio Tools for Docker Desktop for Windows. I've followed the tutorial here. Which helped me make sure that SQL Server is functional and exposed to the outside world.
My preference would be to somehow start docker with NET=HOST and just use . to access my DB. But, I'm not sure how to do that and I'm not sure if that even works on Windows.
Now I can't seem to get the connection right to actually connect to SQL. I've tried these:
Server={MyIPv4Address}:434;Database=MyDB;
MultipleActiveResultSets=true;User
Id=DeveloperLocalHost;Password=MyAwesomePassword
Server={MyIPv4Address};Database=MyDB;
MultipleActiveResultSets=true;User
Id=DeveloperLocalHost;Password=MyAwesomePassword
Server=.;Database=MyDB;
MultipleActiveResultSets=true;User
Id=DeveloperLocalHost;Password=MyAwesomePassword
I've tried many others from tutorials I have looked at online but don't remember them all. I'm a bit perplexed.
I would expect the second method (actual host IP and default 1433 port) to work as long as your SQL instance is configured to allow remote connections. Run this PS command from your container to verify port connectivity:
echo ((new-object Net.Sockets.TcpClient).Client.Connect("MyIPv4Address", "1433")) "connection successful"
Once you verify connectivity, you should be able to start the container with an environment variable and use that for your connection.

Resources