Running PHP on a Windows 2003 Server and connecting to Microsoft SQL Server 2000 Service Pack 4 we found that sometimes the PHP script could connect to the SQL Server but most of the time we’d get ‘mssql_connect() unable to connect to server’.

After Googling the problem I found a lot of references to needing NTWDBLIB.DLL version 2000.80.194.0 rather than the 2000.2.8.0 version that ships with PHP. I copied the DLL from with Windows\system32 folder to the PHP folder and that fixed the problem, for 2minutes! – then we were back to ‘mssql_connect() unable to connect to server’.

I also saw lots of references to Named Pipes and TCP/IP connections so I went into the SQL Server Client Network Utility. Both Named Pipes and TCP/IP were enabled so I changed the protocol order to move Named Pipes above TCP/IP and that fixed the problem – permanently.