Using Tunneling to connect to iprojsrv

Introduction: Why Tunneling?

Some of you may want to connect to our SQL Server database on iprojsrv from your computer at home. However, for security reasons, it is not possible to directly connect to iprojsrv from outside the CSE network. All connections must go through a terminal server.

However, it is possible to create a TCP tunnel, which redirects a TCP connection to a local port on your computer to a remote IP and port, in this case iprojsrv's port 1433. The tunnel can be established as long as you have an SSH connection to one of our department's linux machines.

Creating a tunnel to iprojsrv

For our class, we can use this tunnel in two ways: First, we can install SQL Server Management Studio (the client program for SQL Server) locally, connect to iprojsrv through the tunnel, and directly run SQL queries using a graphical interface. Second, we can write a Java program which establishes a JDBC connection to iprojsrv through the tunnel. In this case we do not need to install SQL Server locally.

In both cases, we first need to create a tunnel. If you are running Windows, you can use a GUI SSH client. If you have a Mac or Linux machine, you can use the command line SSH command.

Using a GUI SSH client

  1. Start your SSH client. If you don't have an SSH client installed, you can download Tectia (formerly called SSH Secure Shell) from http://www.washington.edu/uware. The following instructions are based on Tectia.
  2. Identify a "connection profile" that is going to be associated with your tunneling connection to iprojsrv. Here, we will just use "default-shell" which comes pre-installed with Tectia.
  3. Go to Edit => SSH Tectia Configuration => Connection Profiles => default-shell.
  4. Click the Connection tab. For Hostname, enter attu.cs.washington.edu. For Username, enter your Linux username. Leave the other fields unchanged.
  5. Click the Tunneling tab. Then click the Local Tunnels tab.
  6. Click the Add button. Choose the following settings:
    Type: TCP
    Listen Port: 1433
    Destination Host: iprojsrv.cs.washington.edu
    Destination Port: 1433
  7. Click OK, and then OK again to exit the Tectia Configuration window.
  8. Click on the Profiles button. A drop-down menu will appear. Go to default-shell and click it.
  9. Enter your password for attu.cs.washington.edu to establish the connection.
  10. Leave the SSH Tectia connection window open. You are now all set. If connecting from Java code, please read the "Connecting using JDBC" section below.

Using Command Line SSH

Open a shell and run the following command:
ssh -L 1433:iprojsrv.cs.washington.edu:1433 attu.cs.washington.edu
On windows the above ssh command line client can be replaced with the following clients (not exhaustive):
  1. If you have already installed the SSH Tectia client UWARE tectia, then in additional to the GUI client installed, there is also a command line ssh client installed known as ssh2.exe. This can be found where tectia is installed, probably under "C:\Program Files\SSH Tectia\SSH Tectia Client" or "C:\Program Files (x86)\SSH Tectia\SSH Tectia Client" or perhaps "C:\Program Files\UWICK\SSH Tectia\SSH Tectia Client". Navigate to this directory (or make sure it is in your path) and type the above command, replacing ssh with ssh2.exe. That is:
    ssh2.exe -L 1433:iprojsrv.cs.washington.edu:1433 attu.cs.washington.edu
  2. Download putty and extract/install it to certain directory (assumming the file is authentic). Then navigate to the installed directory and type the above command, replacing ssh with putty.exe. That is:
    putty.exe -L 1433:iprojsrv.cs.washington.edu:1433 attu.cs.washington.edu

Connecting using SQL Server Management Studio 2008

You first need to install SQL Server 2008 locally (note: SQL Server 2005 does not allow you to connect to SQL Server 2008). You can download an evaluation version from Microsoft. You can then start SQL Server Management Studio locally and choose the following connection settings:
Server Name: 127.0.0.1
Authentication: SQL Server Authentication
User: YOUR iprojsrv USERNAME
Password: YOUR iprojsrv PASSWORD
Make sure your SSH connection remains open while you are using Management Studio.

Connecting using JDBC

You can also connect to iprojsrv using JDBC. Again, ensure that you have SSH connection and set up a tunnel as explained above. In your Java code, you can then use the following JDBC connection string
static String connUrl = "jdbc:sqlserver://127.0.0.1:1433;database=imdb;";
You do not need to install SQL Server 2008 on your local machine, if you are connecting using JDBC.