I am getting strange behavior with mssql_connect().

The computer running MS SQL Server is listening on 2 IP addresses: ComputerA on 172.31.250.5 and sql_server on 172.31.250.6.

PHP calling odbc_connect() to ComputerA works.
PHP calling mssql_connect() to ComputerA.example.com works.
PHP calling mssql_connect() to 172.31.250.5 works.

PHP calling odbc_connect() to sql_server works.
PHP calling mssql_connect() to sql_server.example.com produces: Unable to connect to server: sql_server.example.com.
PHP calling mssql_connect() to 172.31.250.6 works.

ASP.NET can also connect to either ComputerA or sql_server.

The web server computer can successfully resolve the host name to IP address; ping works.

Why is mssql_connect() to "sql_server" failing?

    It depends on DNS configuration and server port redirect. It's not the same to access via an URL and via IP. Check the DNS configuration if it's possible in your case.

    Anyways if the server has a dynamic IP you could detect it with URL parameter using PHP, and then use the resulting IP to connect, so it's not a big deal I suppose.

      I don't think the problem is with DNS or reaching the server.
      I ran Microsoft Network Monitor on the SQL Server machine.
      When I successfully connect using ComputerA.example.com, I see this:
      SMB:C; Tree Connect Andx, Path = \ComputerA.example.com\IPC$, Service = ?????
      When I successfully connect using the IP address, I see this:
      SMB:C; Tree Connect Andx, Path = \172.31.250.6\IPC$, Service = ?????
      When I try to connect using sql_server.example.com, I see this:
      SMB:C; Tree Connect Andx, Path = \sql_server.example.com\IPC$, Service = ?????

      So the connection is getting through from the PHP machine to the SQL machine. SQL Server just seems to be rejecting the connection when Path = \sql_server.example.com for some reason.

      It is as if SQL Server does not recognize "sql_server" as belonging to the host computer.
      "ComputerA" is registered on the computer as being its machine name.
      172.31.250.6 is registered on the network card configuration.
      But "sql_server" is only in the DNS server configuration (as an A record); there is no record of "sql_server" in the configuration of the SQL Server computer.

        Write a Reply...