Decoding the "Adaptive Server is unavailable" Error in FreeTDS Connections
When a PHP application attempts to reach a SQL Server instance and receives the error Adaptive Server is unavailable or does not exist, it usually points to a fundamental misalignment between the client's connection parameters and the server's actual network configuration. This specific message originates from the FreeTDS library, which acts as an ODBC bridge for connecting to Microsoft SQL Server from Unix-like environments (such as macOS or Linux).
The error is distinct from a standard "login failed" message because it implies the TCP handshake either never completed or was rejected by the server before any authentication logic could be invoked. In the context of your specific setup, where one database works and another fails with identical FreeTDS and unixODBC configurations, the issue almost certainly lies in how the SQL Server instance is listening on the network, rather than a missing library file or driver version mismatch on the Mac.
The Default Port Misconception
Your freetds.conf configuration explicitly sets port = 1433. This is the default port for SQL Server, but it is not universal. When you connect to a different database using the same host IP (12.34.56.789) and encounter this error while other connections succeed, verify whether that specific instance of SQL Server is actually listening on port 1433.
In many production environments, especially in Windows clusters or multi-instance setups, administrators often reconfigure the default instance to use a dynamic port or a non-standard static port (e.g., 1434 for the Browser service, though that is distinct from data connections) to avoid conflicts with legacy applications or specific firewall rules. If the SQL Server service is configured to listen on 1434 instead of 1433, your FreeTDS driver will attempt to connect to the wrong socket. Since no process is accepting connections on port 1433 at that moment, the TCP connection times out or is refused immediately, triggering the "Adaptive Server is unavailable" response.
You can confirm the listening ports on the server side using the following command:
netstat -an | findstr 1433
If there is no output showing LISTENING for port 1433, but you see an entry for a different port (e.g., 14335), your freetds.conf must be updated to reflect that specific port:
[my_db]
host = 12.34.56.789
port = 14335 ; Change this if the instance is not on the default port
tds version = 8.0
The "Named Instance" Trap
A second common cause for this error involves SQL Server Named Instances. A named instance does not run on port 1433 by default; instead, it listens on a dynamic TCP port assigned at installation. While the Microsoft OLE DB provider and the JDBC driver can often resolve these via the "Dynamic Ports" mechanism or DNS suffixes, FreeTDS is generally more rigid in this regard.
If your target database is installed as MSSQLSERVER (the default named instance) rather than a default instance, it is highly likely that port 1433 is blocked or unused. In such cases, simply changing the port to 1433 will result in the exact error you are seeing. You must identify the dynamic port assigned to the named instance. This can be done on the server by checking the SQL Server Configuration Manager under "SQL Server Network Configuration" -> "Protocols for MSSQLSERVER". If TCP/IP is enabled, the specific dynamic port will be listed.
Alternatively, if you have access to the SQL Browser service (which runs on UDP 1434), FreeTDS can sometimes query this service to resolve the correct port. However, this requires a working DNS setup and often involves configuring port = default in freetds.conf, though this is less reliable for direct IP connections without proper hostname resolution.
Firewall and Network Path Traversal
Finally, ensure that the firewall between your Mac and the SQL Server allows traffic on the specific port you are attempting to use. If the server is listening on a non-standard port (e.g., 14335) but your firewall blocks it while allowing 1433 (where no service exists), the connection will fail with this error. Conversely, if the server is only listening on localhost and you are connecting from an external IP, the connection will be dropped before the "server unavailable" logic kicks in, though the symptom remains identical.
If you are using Laravel or a modern PHP framework that relies on PDO or ODBC drivers for database abstraction, ensure your configuration layer (e.g., config/database.php) does not hardcode a port if the server uses dynamic ports. Passing the correct port from your environment variables or a secure config file is essential when dealing with FreeTDS and non-standard SQL Server instances. For more details on configuring database connections in Laravel applications, you can refer to resources like https://laravelcompany.com.
