Forward SQL Server ODBC over SSH via putty - sql-server

I would like to access a Azure SQL database. It is accessible on port 1433. However, the firewall is blocking this request. Therefore, I wold like to tunnel my connection.
Setup
The client is running on Windows 10. I can connect to a remote linux server. This server runs at home and when I'm at home, I am able to access the SQL database. So I assume my linux server is also able to connect to the Azure database.
Tunnel request?
I want to access the database via an ODBC connection. So, I tried to tunnel the connection using putty:
Putty connects to linux server and tunnels localhost:2433 to server-url:1433
Client connects to localhost:2433
Client has access to database
However, this is not working.
What goes wrong?
I am able to connect using putty to linux server.
I have setup a tunnel inside putty at the Connection > SSH > Tunnels page:
Source port: 2433
Destination: server-url:1433
I have set the radio buttons to Local and auto.
What goes wrong here? I don't know how I can investigate this properly. Maybe there is a problem at my linux server, that it can't connect to Azure SQL. But I think my tunnel is not working correctly. Can you help?

I didn't get it to work with putty, but if you have access to a shell you can use
ssh -L <local_port>:localhost:<remote_port> user#server -i "path to your private key file if you need one for authentification"
So in your specific example it would be
ssh -L 2433:localhost:1433 user#server-url
I used this to create an ODBC connection from RStudio (you can use the built in terminal to establish the tunneling) to a postgres db running in a docker container on azure.

Related

How to Enable TCP/IP for mssql instance in ubuntu 16.04?

I'm not able to connect SQL Server hosted in Ubuntu 16.04 using my program, I believe its because the TCP/IP is disabled for the instance I try to connect (Protocols for SQLEXPRESS under SQL Server network configuration).
How I'm sure because I tried to connect my program to SQL Server that hosted in Windows and it able to connect.
Example my instance name is SQLEXPRESS, so I'm trying to connect through SSMS by using IP Adress\SQLEXPRESS and it fails. But I am able to connect to the SQL if I use IP address only as the server name.
I tried to search about sqlcmd for enable the tcp/ip but all of them just show the guide to change the ports.
So, how can I enable tcp/ip connection for ip\SQLEXPRESS instance in Ubuntu 16.04?
picture below just an example on enabling tcp/ip for the sql instance in windows
I believe the reason why this doesn't work on linux is because it doesn't have a SQL Server Browser application that Windows has available. This application redirects the requests to 1433 to whatever random port it's listening to currently -- this is why it will only connect when the port is specified. In my case this stinks because I'm having to work around an ancient application that we don't have the source code for. I'm thinking about writing a little application that will redirect the default traffic to the correct port for linux msssql.

Connect to database through two ssh tunnels in IntelliJ IDEA

I'm trying to add a postgresql database as a datasource in IntelliJ IDEA Ultimate.
I've worked with a datasource through ONE ssh tunnel already. But now the database server is behind a firewall which only accepts ssh connections from a management server. The only way to access the db server goes over the management server.
So I (or IntelliJ) have to connect via ssh to this server and then, by using another user, tunnel via ssh to the database server.
Everything clear? :-D
The problem is, that IntelliJ offers only to configure one ssh tunnel. But after the first tunnel I need to use a second one, to finally connect to the database server...
Any Ideas?
Thx in advance.
I'd create a local port forward using OpenSSH or any similar tool which will forward 127.0.0.1:2222 to firewall:22 via the Management Server, then use IntelliJ IDEA tunnel configuration to 127.0.0.1:2222 like you would do with the single tunnel.
ssh -L 127.0.0.1:2222:firewall:22 <management server>
You can configure an External Tool to automate this process. On Windows machine I had great experience with Bitvise SSH Client for creating tunnels/port forwards and starting them automatically.
ssh supports your scenario out of the box. The trick is to create two entries in your ~/.ssh/config file for the management server, one for your-user and one for special-user. Then use ProxyJump to chain your connections together.
So, start by setting up a Host section for the management server and the user your are connecting to from your local machine:
Host mgmt
HostName management.server.com
User your-user
...
Then, set up a Host for the user on the management server that you will be logging in as:
Host mgmt-special-user
HostName management.server.com
User special-user
To this same host, add a directive to tell ssh to create a tunnel to your DB:
LocalForward <free-port-on-your-box> <db-ip-or-host>:<db-port>
Then tell ssh that this host can be reached from the first host:
ProxyJump mgmt
You can now ssh mgmt-special-user from your local machine. ssh will automatically jump through the mgmt host, and will also automatically extend the tunnel through mgmt and back to your local machine.
ProxyJump (-J) was added in OpenSSH 7.3 (released in 2016).

Connect to MS SQL Server 2014 from a computer on a different network

I have created an Application in VB.NET with database in MSSQL 2014.
I have configured TCP/IP=1433, UDP=1434, Windows Firewall is configured to allow 1433, 1434, sqlserver.exe, sqlbrowser.exe and server's login settings are configured. Application is working on my laptop which is on the same Internet connection as the host computer. I am trying to use the Application on client computer which is on another network and getting NAMED PIPES PROVIDER error40.
This is connection I am using:
Data Source=myServerName;InitialCatalog=dbName;UserId=clientcomputerName;Password=x
Do I need to configure client's computer in any way?
Does your DNS/HOSTS file resolve the remote computer name? Try IP address instead if not. Not sure but not all versions of SQL support remote connections via Named Pipes (can sometimes get round this by using registry hacks to add the connection as ODBC)

Connect Database to Excel via SSH tunnel

I am trying to connect Excel to my companies database but am running into problems because we use an SSH tunnel. The SSH tunnel connects to Nexcess which is where our servers are stored.
Has anyone else encountered this problem?
Any help is appreciated. Thanks!
Use putty, set up your SSH link to the server.
Under auth select 'allow agent forwarding'
In tunnels set source port to 3306 and then put the domain of your mysql server in the destination followed by :3306 (update this port number if your mysql server is on a different port obviously, but keep the local port the same)
Connect
In mysql workbench, add a new connection: localhost, port 3306, user / pass etc
Then from excel, connect away

To Remotely connect a SQL Database through Internet

I want to connect to a remote computer though internet to connect a SQL Server database. I tried using Teamviewer successfully. Is there any other free tool which can be used in lieu of Teamviewer ?
There are are a few options.
1) Setup up VNC (there are a lot of free VNC implementations). If you set it up, I would recommend setting it up using SSH or some form of encryption so you are secure.
2) Set up a remote vpn connection. If the remote router supports something like DDWRT you can install that and set up you can vpn in to the remote network and access the machine as if you were there locally.
3) Set up port forwarding on the remote router so that when you connect to a specific port (default for SQL server is 1433) it forwards your request to the remote machine and then you just connect to the external IP of the remote router.
4) Set up port forwarding for Windows remote desktop. Basically the same as #3 except a different port and you'd use RDP to connect to the machine first instead of SQL server.
You can use MySQL Workbench tool for this purpose .. it's really simple ...
Just configure a new connection with the tool and you get to access the database remotely...
Just connect directly using SQL Server authentication
Update: or use trusted connection through VPN (IPSec).
If this question involves connection to SQL Server through internet. If not, then it is not development question and does not belong to SO.

Resources