Elisa
Elisa

Reputation: 7103

ssh tunnel do not work for mssql_connect()

Why mssql_connect() can not connect to mssql database with tunnel.

I have created tunnel for remote server like:

$ssh -L 1433:db_server:1433 user@mid_server

This forward the local port 1433 to db_server. I tested.

However when I try to connect to database using php it does not work

mssql_connect("localhost:1433", 'db_user', 'db_password')

Detail (edited):

  1. db_server : Remote database server where sql server is installed. DB server has firewall. Only mid_server can connect
  2. mid_server : Middle where which is allowed to connect db_server

Upvotes: 1

Views: 838

Answers (2)

Elisa
Elisa

Reputation: 7103

I got it fixed it by make some changes on freetds.conf

[global]
    # TDS protocol version
;   tds version = 4.2

to

[global]
    # TDS protocol version
tds version = 7.0

and restart apache.

Upvotes: 1

Capilé
Capilé

Reputation: 2088

I assume you are connecting from a linux (or MacOS) box to MSSQL server, probably using freetds connector. Two things need to be checked: if the server is properly listening to the port and if FreeTDS is properly installed on the Linux machine. Since you can connect with another client, the problem should be on FreeTDS.

Make sure FreeTDS is installed and properly configured. Try to connect to the server directly with (it should prompt for password):

# tsql -S localhost -U db_user

If necessary, adjust the port/locale/version information on freetds.conf. For more information:

Upvotes: 0

Related Questions