Wednesday, June 8, 2011

[Tips & Trick] PHP Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server:

As the title stated, quite a troublesome issue here at my work. Wasted quite enough time for Me to take a nap :P

All was started when Me got assigned to move certain web server to a new machine. The configurations are PHP inside the Mikocok Internet Information Services (IIS for short) using ISAPI and Mikocok SQL Server 2005 Express.

To make the story short, all preparation had been done. The MS-SQL is up and running. PHP installed using manual process, that's Unzipping the ZIP Package to C:\php, set the Windows' Path to Include it, Modified the php.ini to enable MSSQL and LDAP extensions, adding windows' Environment Variables (PHPRC=C:\php). Set the IIS to use PHP5ISAPI.DLL as a binding to PHP compiler and set the ".php" as the file extension used for PHP. Me also have checked the PHP configuration through function. All is well according the phpinfo data.

And then the merit paid-off... :(

All Me did was trying to connect to the MS-SQL DB and the Error Message goes:
PHP Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server:
Trying was all Me could do as quickly as Me could. Googling (if it even a word :D), Checking all the configs, the required files and even reinstalling the entire system to make sure all is mimicking the old one. None of them to bare any fruit.

And so days gone by to weeks, while the user is reverted to the old system. But managements are still at Me wit until this very day, when me come back to uncle Google to have another session. Finally, there's an article which me have failed to see before. Its' all about the version of one particular file which is used by the IIS to communicate with the MS-SQL DB. The One and Awesome:
NTWDBLIB.DLL (cheers and applause...!!!!)
as the article (you can find it here) said that:
"...ntwdblib.dll Version - On some systems the ntwdblib.dll version is too old to work correctly with PHP. If your version does not end in 80.194.0 it's probably too old..."
And so me check... Indeed Me version was still 2000.2.8.0! You could find this by pressing Alt+Enter at C:\php\ntwdblib.dll file.

And so Me download the file from the link provided in the above article, replace the file and Restart the IIS.And so Me problem solved. The Application is up and running now, with the DB Connection issue resolved.

For backup purpose, there was also a Mirror of the file to DOWNLOAD HERE.

No comments: