microsoft / dev-tunnels

Dev Tunnels SDK
MIT License
293 stars 21 forks source link

Is it possible to access a local sql server instance using DevTunnel? #487

Open gabbidonn opened 2 weeks ago

gabbidonn commented 2 weeks ago

I was hoping to temporarily create a tunnel to my local sql server instance, but it doesn't seem to be successful.

I'm creating a tunnel on host 1433 and allow anonymous access temporarily. So the commands are as follows:

devtunnel host -p 1433 -a

I'm then using the host I get back to try and gain access. Something seems to be blocking it still. I presume TCP is not supported. Is there a way to support this?

derekbekoe commented 2 weeks ago

On the other end of the tunnel you should be able to use devtunnel connect TUNNELID to connect to the tunnel.

gabbidonn commented 2 weeks ago

I've done that. I see port 1435 is then used for forwarding. It doesn't make a difference when I try to connect to sql server using the hostname.

derekbekoe commented 2 weeks ago

when I try to connect to sql server using the hostname.

Can you share more details on your set up? What does "using the hostname" mean here?

gabbidonn commented 2 weeks ago

Hi.

So I'm creating the tunnel using the following:

devtunnel host -p 1433 -a

Once I do that, get the hostname, something like tunnelid.uks1.devtunnels.ms

I am attempting to use that to access my instance remotely, using a normal sqlcmd similar to the following:

sqlcmd -S tcp:tunnelid.uks1.devtunnels.ms,1433

After you mentioned the connection, I have then done the following on the node where I'm trying to connect:

devtunnel connect tunnelid

Which gives me the following:

Connected to tunnel: tunnelid SSH: Forwarding from 127.0.0.1:1435 to host port 1433. SSH: Forwarding from [::1]:1435 to host port 1435. SSH: PortForwardingService listening on 127.0.0.1:1435. SSH: PortForwardingService also listening on ::1:1435.

I'm currently just trying to connect on my local machine for now, where I've setup the tunnel to 1433, and I'm now looking to connect to it.

I'm starting to suspect that only https and http is supported... however if I'm wrong, and this is possible then I'm happy to be corrected.

Thanks.

derekbekoe commented 2 weeks ago

Thanks for the context.

I would not expect the sqlcmd -S tcp:tunnelid.uks1.devtunnels.ms,1433 command to succeed.

On you client, you can dodevtunnel connect tunnelid which will indicate the port it's listening on, e.g. 1435. Then, from that same client, you should be able to run a command like sqlcmd -S tcp:localhost,1435. This would connect to the local port 1435 that's being tunneled via dev tunnels to the port 1433 on your host machine.

gabbidonn commented 1 week ago

@derekbekoe thanks for that. I understand further. It doesn't completely suit my needs because I wanted to access it via remote hostname. But if I can access the node that has connected to the devtunnel remotely, using the port that has been setup (in the example case, 1435) then that will work I presume. I will try this.