"Adaptive Server is unavailable or does not exist" error connecting to SQL Server from PHP
Solution 1
1. See information about the SQL server
tsql -LH SERVER_IP_ADDRESS
locale is "C"
locale charset is "646"
ServerName TITAN
InstanceName MSSQLSERVER
IsClustered No
Version 8.00.194
tcp 1433
np \\TITAN\pipe\sql\query
2. Set your freetds.conf
tsql -C
freetds.conf directory: /usr/local/etc
[TITAN]
host = SERVER_IP_ADDRESS
port = 1433
tds 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.
Solution 2
After countless hours of frustration I managed to get all working:
odbcinst.ini:
[FreeTDS]
Description = FreeTDS Driver v0.91
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
fileusage=1
dontdlclose=1
UsageCount=1
odbc.ini:
[test]
Driver = FreeTDS
Description = My Test Server
Trace = No
#TraceFile = /tmp/sql.log
ServerName = mssql
#Port = 1433
instance = SQLEXPRESS
Database = usedbname
TDS_Version = 4.2
FreeTDS.conf:
[mssql]
host = hostnameOrIP
instance = SQLEXPRESS
#Port = 1433
tds 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!
Solution 3
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).
Solution 4
I had the same issue, my problem was that the firewall on the server wasn't open from the current ip address.
Solution 5
Responding because this answer came up first for search when I was having the same issue:
[08S01][unixODBC][FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist
MSSQL named instances have to be configured properly without setting the port. (documentation on the freetds config says set instance or port NOT BOTH)
freetds.conf
[Name]
host = Server.com
instance = instance_name
#port = port is found automatically, don't define explicitly
tds version = 8.0
client charset = UTF-8
And in odbc.ini just because you can set Port, DON'T when you are using a named instance.
Comments
-
wonder95 almost 2 years
I'm attempting to connect to a SQL Server 2005 DB from my Mac using unixODBC and FreeTDS as I have outlined here. However, when I try to connect in to a different DB using the same setup, I get:
Connection Failed:[FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist.
Here is my freetds.conf setup:
[my_db] host = 12.34.56.789 port = 1433 tds version = 8.0
And here is my odbc.ini:
[my_dsn] Driver = /opt/local/lib/libtdsodbc.so Description = My Database Trace = no Servername = my_db Database = MyDB [ODBC Data Sources] my_dsn = FreeTDS
I am still able to connect to the other DB I set up on this computer (described in my blog post linked above), so I'm pretty sure that the error isn't on the Mac end. I've verified on the server that I'm using the correct IP address and port. Any thoughts on what could be the problem, and if it's on the server end?
-
shorif2000 about 11 years
TDSVER=8.0 tsql -S *serverIPAddress* -U *username* -P *password*
this works for me but in freetds makes no difference -
Adversus over 8 yearsThanks for this, I needed to specify the port (
ip:port
for pymssql) and the LH command allowed me to easily find it. -
brad over 6 yearsIf tsql -LH gives no output, what is the next step that should be taken?
-
Murwa about 5 yearsAwesome. Saved my day.
-
Adrian Keister over 4 yearsIf you're trying to connect to a database on a different machine, this answer will not help at all.
-
Adrian Keister over 4 years@Jan: That web site is no longer available.
-
Adrian Keister over 4 years@Naidim: What are the possible values for instance? That doesn't seem to be in the documentation, and I have a funny feeling mine isn't SQL Express.
-
Adrian Keister over 4 yearsIs it also possible that odbc isn't installed correctly? What are the correct steps on, say, Ubuntu?
-
Adrian Keister over 4 years@EvgeniyTkachenko: Sometimes the LH command does not return anything, even though the address is correct. Is LH deprecated?
-
Jan over 4 years@AdrianKeister check the name of your SQL Server instance see these answers stackoverflow.com/questions/16088151/…
-
Evgeniy Tkachenko over 4 years@Adrian Keister I use FreeTDS(May 14, 2011) (
man tsql
) .I didn’t get your problem. -
Pamungkas Jayuda over 2 yearsi think this answers not relevan