MS SQL (SQL Server) access to instances requires a static port for Linux or IBM i connections

Follow

Issue

Attempts to connect PHP to a named instance fail for operating systems other than Windows.

Environment

PHP running on any operating system other than Windows.

Resolution

In Windows, setting up a connection to an MS SQL (SQL Server) named instance can be accomplished using the instance name. For example, an instance named INSTANCE1 found at IP address 192.168.15.17 might be specified like this:

$servername = '192.16.15.17\INSTANCE1';

$mssql_conn = mssql_connect($servername,"user","password");

Versions of PHP that do not run on Windows (like Linux and IBM i) cannot use the named instance to connect to MS SQL. Instead, MS SQL needs to be configured to use a different port for each instance, so you can use that port to make the connection. For example, the default instance of MS SQL is typically at port 1433, so to connect to the default instance:

$servername = '192.16.15.17:1433';

If named instance INSTANCE1 was at port 1435, your connection server would look something like this:

$servername = '192.16.15.17:1435';

Work with your MS SQL administrator to learn the port for the needed instance, and then connect to that port. MS SQL may be configured to assign a port dynamically, in which case the MS SQL configuration would need to be changed by your MS SQL administrator to assign a static port for this instance, to give you an unchanging port number you can use in your script.

Instructions for how to configure a SQL Server instance to listen on a specific port can be found here:

Configure a Server to Listen on a Specific TCP Port

 

 

Have more questions? Submit a request

Comments

Powered by Zendesk