1

I am trying to connect one of our clients "as is" programs to a remote database instead of a local one, they think that they have coded it to work that way, but for some reason the program crashes when trying to connect to a remote database. I don't have the source code so I can't really dig much deeper than that and the company does not provide any upgrades or custom modifications. I can successfully connect to the database through SqlDbx and HeidiSQL so I know that the server is set up correctly.

This is why I need to find a way to spoof a remote connection on port 1433 to appear like a local database connection to the program. I thought about editing the hosts file, but it will most likely crash other programs if I bind localhost to another IP than 127.0.0.1.

Any ideas?

UPDATE:

I've tried solving it other ways like suggested, but I've tried everything I can think of.

  • It's the same versions of all the programs
  • TCP/IP works instead of Named pipes on localhost and works with sqlviewers like SqlDbx and HeidiSQL
  • Authentication works with sqlviewers
  • The configuration is only the fields needed for the database connection string

The only thing that I can see is left is that there is something restricting it from inside the code which I have no control over.

4
  • 1
    If the program is capable of connecting to a remote database but crashes when trying to connect why don't you work on resolving that problem instead of trying to "hack" a solution? If you're having trouble finding the cause of the problem then go to the vendor and get their assistance. This seems like a misguided method for fixing the problem.
    – joeqwerty
    Nov 11, 2013 at 4:53
  • @joeqwerty: I don't have access to the source code and the company developing it does not provide any custom modifications. I don't see any other solution to this than doing a hack.
    – spydon
    Nov 11, 2013 at 4:56
  • I don't understand. You stated that the program has been coded to be able to connect to remote databases, so why would you need access to the source code? Why would the vendor need to provide a "custom" modification? The program is capable of connecting to a remote database, according to you, so why not work with the vendor to troubleshoot it?
    – joeqwerty
    Nov 11, 2013 at 16:43
  • 1
    I wouldn't call the people who wrote the program professionals, they barely know how to code but somehow they manage to sell this program. When they say that they have coded it to be able to do something it's more of a guess from their side and we have to find out if it's true or not.
    – spydon
    Nov 11, 2013 at 22:23

3 Answers 3

3

Essentially, you're trying to work around what appears to be somebody else's bad implementation. That seems reasonable to me, and sometimes, that's a necessity. If this program is indeed "crashing" when trying to connect to one database but not another, as opposed to, oh, you know, displaying an error message, that's pretty weak.

I have a standby solution for this in Linux ("redir") ... but not Windows; however, I found this in the Google machine:

http://www.vakuumverpackt.de/tcptunnel/

I tested it just now with the "Cygwin" version -- no install required, it has an exe and a DLL and it "just worked" on my Windows 7 laptop. Neat little bonus, it has a --log-to-stdout option which, combined with > into a file, logs the bytes sniffed from the stream (might be interesting reading). I didn't have a SQL Server handy, but I tested it with some other TCP services and it seems to work as intended -- it listens on a local socket, and when connections come in, it makes a connection to a designated socket on a remote machine, and ties the ends of the pipes together. Listening on 1433, it "should" do the trick.

It's going in my toolkit, anyway.

0
3

While you certainly could use techniques like SSH port forwarding to make a remote listening TCP socket appear like a local one, it probably would not be of any help.

If your client is "crashing" upon connection, it most likely would not stop doing so just because you are using a different destination IP address.

There might be a myriad of reasons why the software is running fine when connecting to a local database but becomes troublesome with a remote database, including but not limited to

  • version issues
  • use of different protocols (Named pipes vs. TCP/IP)
  • authentication issues (integrated authentication might work locally but break for remote systems)
  • configuration issues

You should direct your efforts towards the problem's diagnosis instead of doubtful workaround attempts.

1
  • I agree that this should be solved another way, but I've tried everything I can think of. It's the same versions of all the programs, TCP/IP works instead of Named pipes on localhost and with works with sqlviewers like sqldbx and heidisql, authentication works with sqlviewers, the configruation is only the fields needed for the database connection string.
    – spydon
    Nov 12, 2013 at 1:31
1

The other answers seem to suggest you should get the application fixed - this is not always possible in reality, so here's a bit of a band-aid/paper clip/bubble gum fix.

I haven't tried this with MSSQL, but for MySQL, I was able to configure TCP proxying via Nginx. The setup would be to deploy Nginx on the same box as your application, with config like that in this SO answer; hopefully it'll work for you just by changing the ports to 1433:

stream {
  upstream db {
    server mssql.example.com:1433;
  }

  server {
    listen 1433;
    proxy_pass db;
  }
}

EDIT: If using named instances and SQL Browser service (which uses UDP) is involved, you can also add a config for UDP proxying: https://dev.to/jordonr/reverse-proxy-ms-sql-with-nginx-3e90

stream {
    upstream dbtcp {
        server db1:1433;
    }

    upstream dbudp {
        server db1:1434;
    }

    server {
        listen 1433;
        proxy_pass dbtcp;
        proxy_connect_timeout 1s; # detect failure quickly
    }

    server {
        listen 1434 udp;
        proxy_pass dbudp;
        proxy_connect_timeout 1s; # detect failure quickly
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .