Connect to MSSQL on Linux ?! Can i ?


How to connect or test MSSQL connection from Linux Command Line ?

There are several ways to do so but for me i am using the following:

First install FreeTDS and UnixODBC:

yum search unixODBC
yum install unixODBC
yum install freetds

Then you can use "tsql" , below is an example and you can use also -h for help:

tsql -H  ServerIP_HERE  -U userName  -P passWord  -p 1433

FreeTDS(May 14, 2011)                                    

       tsql - utility to test FreeTDS connections and queries

       tsql   { -S servername [-I interface] | -H hostname -p port }
              -U username [-P password] [-o options]

       tsql   -C

       tsql  is  a diagnostic tool provided as part of FreeTDS. It uses the TDS protocol directly to con-
       nect to Sybase or Microsoft SQL Servers, and allows the user to issue queries that test the  capa-
       bilities of FreeTDS.

       tsql  is  *not* a replacement for a complete isql, such as sqsh (  It is designed to
       rely on the lowest level FreeTDS library, tdslib, as a way to isolate potential bugs in the proto-
       col implementation.

Below is a very simple php script which can test a MSSQL Connection from Linux server to external server to see if it's successful or not:

[code]<?php // Change ip.ip.ip.ip below with the destination server ip $server = 'ip.ip.ip.ip'; // Connect to MSSQL , change user with username and pass with the password $link = mssql_connect($server, 'user', 'pass'); if (!$link) { die('Something went wrong while connecting to MSSQL'); } else { echo "connected successfully\n"; } ?>[/code]