"Adaptive Server is unavailable or does not exist" error connecting to SQL Server from PHP "Adaptive Server is unavailable or does not exist" error connecting to SQL Server from PHP sql-server sql-server

"Adaptive Server is unavailable or does not exist" error connecting to SQL Server from PHP


1. See information about the SQL server

tsql -LH SERVER_IP_ADDRESSlocale is "C"locale charset is "646"ServerName TITANInstanceName MSSQLSERVERIsClustered NoVersion 8.00.194tcp 1433np \\TITAN\pipe\sql\query

2. Set your freetds.conf

tsql -C    freetds.conf directory: /usr/local/etc[TITAN]host = SERVER_IP_ADDRESSport = 1433tds version = 7.2

3 Try

tsql -S TITAN -U user -P password

OR

 'dsn' => 'dblib:host=TITAN:1433;dbname=YOURDBNAME',

See also http://www.freetds.org/userguide/confirminstall.htm (Example 3-5.)

If you get message 20009, remember you haven't connected to the machine. It's a configuration or network issue, not a protocol failure. Verify the server is up, has the name and IP address FreeTDS is using, and is listening to the configured port.


After countless hours of frustration I managed to get all working:

odbcinst.ini:

[FreeTDS]Description = FreeTDS Driver v0.91Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.soSetup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.sofileusage=1dontdlclose=1UsageCount=1

odbc.ini:

[test]Driver = FreeTDSDescription = My Test ServerTrace = No#TraceFile = /tmp/sql.logServerName = mssql#Port = 1433instance = SQLEXPRESSDatabase = usedbnameTDS_Version = 4.2

FreeTDS.conf:

[mssql]host = hostnameOrIPinstance = SQLEXPRESS#Port = 1433tds version = 4.2

First test connection (mssql is a section name from freetds.conf):

tsql -S mssql -U username -P password

You must see some settings but no errors and only a 1> prompt. Use quit to exit.

Then let's test DSN/FreeTDS (test is a section name from odbc.ini; -v means verbose):

isql -v test username password -v

You must see message Connected!


It sounds like you have a problem with your dsn or odbc data source.

Try bypassing the dsn first and connect using:

TDSVER=8.0 tsql -S *serverIPAddress* -U *username* -P *password*

If that works, you know its an issue with your dsn or with freetds using your dsn. Also, it is possible that your tds version is not compatible with your server. You might want to try other TDSVER settings (5.0, 7.0, 7.1).