MSSQL Connection Failure from Linux (FreeTDS / DBLib)

Follow

Applies to:
Zend Server 9
Linux - RPM
Microsoft SQL Server

Problem

When connecting through PDO_DBLIB (FreeTDS) to MSSQL with protocol 7.x / 8.0, you might get a connection failure when not setting TCP port.

Technical

The FreeTDS library will default to port 4000 instead of 1433, so without explicit definition it will not connect to default port on MSSQL.

Solutions

1. Configure freetds.conf to include the port to MSSQL (i.e. 1433)

[10.9.178.47]
host = 10.9.178.47
port = 1433
tds version = 8.0

2. Define port under HOST in PDO connection strings

$dbh = new PDO ("dblib:version=8.0;host=$hostname:1433;dbname=$dbname","$username","$pw");
Have more questions? Submit a request

Comments

Powered by Zendesk