یہ صفحہ ابھی اردو میں دستیاب نہیں ہے۔ اسے انگریزی میں دکھایا جا رہا ہے۔
Reach Microsoft SQL Server through Localtonet
اس صفحے پر 9 سیکشنز
- How it works
- Before you start
- Create the tunnel
- Open the TCP - UDP page
- Fill in the form
- Start the tunnel and copy the address
- Connect from outside
- SQL Server Management Studio
- sqlcmd
- Connection string
- SQL Server settings that matter behind a tunnel
- Turn on TCP/IP and use a fixed port
- Allow SQL Server Authentication
- The instance sees the Localtonet client as the source
- Keep the same address
- Secure it
- Common problems
- Related pages
Connect to a SQL Server instance on your machine from another network with SSMS, sqlcmd or your application: a TCP tunnel gives port 1433 a public host name and port.
How it works #
The Localtonet client runs on the machine that hosts SQL Server, or on another device in the same network. A TCP tunnel points to the SQL Server port, 1433. Localtonet gives the tunnel a public address made of a host name and a port. A SQL Server client that connects to that address reaches your instance. The details of TCP tunnels are on the TCP page.
SQL Server writes the port after a comma. In SSMS, sqlcmd and connection strings the address is <TUNNEL_HOST>,<TUNNEL_PORT>, not host:port.
Before you start #
- A Localtonet account and the Localtonet client connected with your AuthToken. See Quick start.
- A SQL Server instance that accepts TCP connections on a fixed port. See SQL Server settings below: on Express and Developer editions TCP/IP is off by default.
- A SQL Server login with a strong password. Windows Authentication normally doesn't work for a client outside your Windows domain, so remote clients sign in with SQL Server Authentication.
Create the tunnel #
-
Open the TCP - UDP page #
Open My Tunnels › TCP - UDP and expand Create TCP - UDP Tunnel.
-
Fill in the form #
Field What to enter Protocol TCP Device token The token the Localtonet client on the device uses. Server region Choose a region close to your device for lower latency. Local IP address 127.0.0.1when SQL Server runs on the same device as the client. For an instance on another machine in the network, enter that machine's address.Local port 1433, or the TCP port you set for the instance.URL type Random subdomain. Custom subdomain lets you choose the name and needs Balance. Select Create tunnel.
-
Start the tunnel and copy the address #
The tunnel appears under Your tunnels. Select Start. The URL column shows the public address as
host:port, and the Server Port column shows the port on its own. Note both parts: you will join them with a comma.
Connect from outside #
SQL Server Management Studio #
- In Connect to Server, enter
<TUNNEL_HOST>,<TUNNEL_PORT>in Server name. - Set Authentication to SQL Server Authentication and enter the login and its password.
- Select Connect.
sqlcmd #
sqlcmd -S tcp:<TUNNEL_HOST>,<TUNNEL_PORT> -U <DB_USER> -d <DB_NAME>sqlcmd asks for the password when you leave out -P.
Connection string #
Server=tcp:<TUNNEL_HOST>,<TUNNEL_PORT>;Database=<DB_NAME>;User Id=<DB_USER>;Password=<DB_PASSWORD>;Encrypt=True;With Encrypt=True the client checks the server's certificate against the name you connect to. A default SQL Server installation uses a self-signed certificate, which doesn't match the tunnel's host name, so the connection fails with a certificate error. For a test, add TrustServerCertificate=True; (in SSMS: Trust server certificate). The session is still encrypted, but the server's identity is not verified. For regular use, install a certificate on SQL Server for the name your clients connect to.
SQL Server settings that matter behind a tunnel #
Turn on TCP/IP and use a fixed port #
In SQL Server Configuration Manager, open SQL Server Network Configuration › Protocols for <INSTANCE> and enable TCP/IP. In its properties, on the IP Addresses tab under IPAll, clear TCP Dynamic Ports and set TCP Port to 1433. Restart the SQL Server service. Named instances such as SQLEXPRESS use a dynamic port until you do this.
Connect by port, not by instance name. A name such as <TUNNEL_HOST>\SQLEXPRESS is resolved through the SQL Server Browser service on UDP port 1434, which this tunnel doesn't forward.
Allow SQL Server Authentication #
In SSMS, open the server's Properties › Security and select SQL Server and Windows Authentication mode, then restart the service. Create a login for remote use with only the permissions it needs. Don't use sa.
The instance sees the Localtonet client as the source #
Connections arrive from the Localtonet client on your device, so SQL Server only has to accept local connections, and Windows Firewall doesn't need an inbound rule for port 1433 from the internet. It also means that firewall rules and logon triggers that filter by client address can't tell visitors apart. Limit the visitors on the tunnel instead, with IP Restriction.
Keep the same address #
The host name stays with the tunnel. The port is assigned by the server when the tunnel starts. With Is Reserved? on in the tunnel's Settings, the port stays the same when the tunnel or the Localtonet client restarts, which is what a connection string needs. With it off, the port changes on a restart. Tunnels that you create while your account has Balance start with Is Reserved? on. Turning it on needs Balance and a started tunnel.
With Balance you can also choose the port under Server Port › Change, for example 1433 if no other tunnel on that server uses it. Clients can then leave out the port. See Ports.
Free plan. A TCP tunnel stops after 30 minutes on the Free plan and can be started again. The port can be different after each start. See Plans and Balance.
Secure it #
Do not expose a database without access control. A started tunnel is reachable by anyone who has its address, and SQL Server logins are a common target for password guessing.
- IP Restriction. In the tunnel's Settings, select IP Restriction › Manage, choose Allow only these and add the addresses of the applications and people that connect. Use my IP fills in your current address. Changes apply right away. IP Restriction needs Balance. See Access control.
- A dedicated login with a strong password and the smallest set of permissions. Disable or rename
sa. - Encrypted connections. Tunnels are not encrypted end to end by default, so keep
Encrypt=Truein your connection strings. - Limits. Expiration Date, Bandwidth Limit and Speed Limits in the tunnel's Settings cap how long and how much the tunnel can be used. See Limits and expiration.
- Request Log › Show lists the connections made to the tunnel with the visitor's IP address.
Common problems #
"A network-related or instance-specific error occurred" (error 53, 40 or 10060)
The client could not open a connection. Check that you wrote the address with a comma (host,port), that the tunnel is started and its Connection column shows ON, and that you use the current port from Server Port. Then check on the device that TCP/IP is enabled and that the instance listens on the tunnel's Local port.
"The certificate chain was issued by an authority that is not trusted"
The tunnel works. The client refuses SQL Server's self-signed certificate. See the note about TrustServerCertificate under Connection string.
"Login failed for user" (error 18456)
The tunnel works and SQL Server answered. Check the password, that the login is enabled, and that the server allows SQL Server Authentication.
The application lost its connection after a restart
The port is not reserved, so it changed when the tunnel or the client restarted. Turn on Is Reserved?, or update the port in the connection string.
The tunnel stopped by itself after half an hour
On the Free plan a TCP tunnel stops after 30 minutes. Select Start to begin another session, or add Balance to remove the session limit.
"You need to purchase balance to use this feature."
Is Reserved?, Server Port, IP Restriction and Custom subdomain need Balance. Add it under Balance.