php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40034 mssql_connect(): Unable to connect to server
Submitted: 2007-01-05 15:23 UTC Modified: 2016-10-15 23:10 UTC
Votes:92
Avg. Score:4.3 ± 1.0
Reproduced:73 of 77 (94.8%)
Same Version:41 (56.2%)
Same OS:45 (61.6%)
From: chris dot clos at lmcu dot org Assigned:
Status: Wont fix Package: MSSQL related
PHP Version: 5.2.0 OS: Windows Server 2003
Private report: No CVE-ID: None
 [2007-01-05 15:23 UTC] chris dot clos at lmcu dot org
Description:
------------
I have PHP 5.1.4 and upgraded to php 5.2.0.  Copied my php.ini file over.  I use IIS in Server 2003 (Standard) SP1, connecting to SQL Server 2005 (Standard).  

I can no longer do mssql_connects, instead I get an error.

Once I did this I get an error: 

PHP Warning:  mssql_connect(): Unable to connect to server:  x.x.x.x in C:\db-test.php on line 3

This is the same thing that happens when using it via IIS (using php5isapi) or the php command line.  This does work on a Windows XP SP2 machine just fine.  I can reproduce this other Windows Server 2003 machines.  

I read from bug Id 39313, and I have tried loading the client tools, however I do not see anywhere that there is a NETBIOS or a TCP/IP type setting in SQL Server Management Studio.  

After looking long and deep, I found that its the version of ntwdblib.dll that is provided with php package.  I found one that is version "2000.80.194.0" that fixes it, but the one included is "2000.2.8.0"

Same problem appears to happen with 5.1.4 and this version of dll, I think this file needs to be updated in the distribution.

Reproduce code:
---------------
<?php

$dbh = mssql_connect('x.x.x.x','user','password');

if($dbh) {
 echo "true\r\n";
} else {
	echo "fubar\r\n";
}
?>


Expected result:
----------------
I should get "true" printed out.

Actual result:
--------------
Using 5.2.0:
Warning: mssql_connect(): Unable to connect to server:  x.x.x.x in C:\db-test.php on line 3
fubar


Using 5.1.4:
true

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-12 14:11 UTC] edink@php.net
Sorry, I'm not the MSSQL intiated :)

Frank, could you take a look please?
 [2007-01-12 16:30 UTC] fmk@php.net
But you are packing the dll's :-)

As far as I know different versions of ntwdblib.dll will default to either tcpip or netbios for the default protocol. There might also be a registry setting for this (I'll look for that tonight when I get home).

Just copying the dll to the system does not give you access to the client configuration tools that allow you to change the defaults or create server aliases that should be used as the host parameter for mssql_connect().

If the newer version of ntwdblib.dll solves the problem I'd say we should bundle it.
 [2007-01-22 21:18 UTC] tschoenbachler at eoncc dot com
I too has seen this problem on one of my customers machines and FYI, restarting IIS temporarily fixes the problem. As a work around can I do a regsvr32 on the new ntwdblib.dll and if so where can I get it...?
 [2007-01-23 05:36 UTC] ivanvart at gmail dot com
We have the same problem... we solved (but we dont know if is the best option) changing the ntwdblib.dll (ver. 2000.80.2039.0) in the php directory.
 [2007-06-30 18:34 UTC] jmckinzie at novonics dot com
I may be having some similar behavior related to this bug. I'm having issues with database connections dropping on a Win 2K3 box, running Apache 1.3.37, PHP 5.1.6 and MS SQL 2005 Express. I am able to connect most of the time using mssql_connect. However, on a consistent basis, probably 15-45 minutes, my mssql_connect calls begin to fail with the same message as above:

PHP Warning:  mssql_connect(): Unable to connect to server:  x.x.x.x

Restarting Apache fixes the problem and I am able to connect for a short time. I'm using ntwdblib.dll, version 2000.80.194.0, and have not upgraded to 2000.80.2039.0.
 [2008-07-23 00:01 UTC] efesar at gmail dot com
Recently I upgraded to PHP 5.2.6 (Apache 2.2.9, Win2003 SP2, MSSQL 2000 SP4 on a separate box) from 5.1.2 (Apache 2.0.58) and this problem suddenly reared its ugly head. Apache wouldn't connect to the database for more than a few hours. PHP was running the "2000.2.8.0" DLL ... I copied the "2000.80.2273.0" DLL over from the MSSQL 2000 box and restarted the web box. 

I'm hoping this fixes the issue. We tried to use Microsoft's 2005 PHP driver, but it was hopelessly bad at managing resources (If we ran more than 15 calls to sqlsrv_query() in a single PHP session, it crashed PHP and Apache consistently). 

So far, so good. If this solution doesn't work within 72 hours to fix the problem, I'll come back to add another comment so that people reading this bug report will know it's still a problem. Otherwise, if I'm not back in a week or so, assume the DLL swap is the fix. 

Incidentally, we also run a PostgreSQL box. We connect to both MSSQL and PGSQL from the same web server, and the PGSQL connection has never failed.
 [2008-07-29 12:37 UTC] c dot pasticcio at gawab dot com
We have the same problems with sevral configurations on windows 2003.
- webserver: win2k3 + Apache 2.2.9 + Php 5.2.6
- webserver: win2k3 + Apache 2.0.59 + Php 5.1.6
- db server: win2k3 + sql server 2000

We have other 2 webservers with latest Apache and Php releases running on windows 2000 that don't suffer this problem.

On all webservers we have ntwdblib.dll version 2000.80.194.0.
On db server with win2k3 we have a ntwdblib.dll version 2000.80.2039.0.
We didn't try to change the libs yet.
 [2008-08-15 11:51 UTC] php at blazemonger dot com
I am experiencing this on Linux (CentOS 5) with the stock PHP 5.1.6 and PHP 5.2.6.  It is intermittent -- the same SQL query to the same DB server will work sometimes, fail other times.
 [2008-09-18 13:14 UTC] spanidis at certh dot gr
Hello to everyone.

Could you please tell us where can we download ntwdblib.dll (ver. 2000.80.2039.0) from? 

Thanks for your help

Pavlos
 [2008-10-10 08:35 UTC] dirk dot melcher at mdk-nord dot de
thanks everybody for the hints that helped me a lot!

I'm using php Version 4.2.1 and the same problem applied to me.
I downloaded an appropriate version of ntwdblib.dll at:

http://www.dlldll.com/ntwdblib.dll_download.html

Bye,

Dirk
 [2008-10-10 10:40 UTC] hamzeh dot shaar at ifpexpo dot com
Guys, I have the same problem. I have php 5.2.6 on IIS 6.  I cannot connect from it my SQL server 2000 (MSDE) running on the same machine knowing that i have another PHP installation 5.2.5 on the same LAN and it connects to the same MSDE 2000 Normally.

I tried copying php5isapi.dll and ntwdblib from the working machine to the other and still it dd not work.

any suggesstions?
 [2008-12-11 19:51 UTC] parvesh_k at hotmail dot com
I have a windows dll version 2000.80.194.0 and use php 5.2.6

I am trying to connect to MSQL2K5 but get a following error "Unable to connect to server: "

I have following option turned on mssql.secure_connection = On in php.ini
 [2009-06-08 16:36 UTC] wrossmann at gmail dot com
Same issue under 5.2.1.1, solved as above. We deploy this same solution to dozens of IIS6/PHP servers with several hundred domains and have not detected any apparent incidental functionality issues.
 [2009-07-06 11:07 UTC] nm dot patel at sahmed dot com
I have PHP Version 5.2.10 i have open mssql support from  php.ini .  I use IIS in Server 2005 Express 

I can no longer do mssql_connects, instead I get an error.

Once I did this I get an error: 


Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost:1433 in C:\Inetpub\wwwroot\LifeScience\TEST.php on line 8
Couldn't connect to SQL Server on localhost:1433
 [2009-10-19 16:05 UTC] guoxinzz at 163 dot com
A temporary solution, the real problem is not found. 
Explore the question, please contact my technical blog 
http://blog.csdn.net/gumanren 
My E-mail:guoxinzz@163.com or guoxinzz@gmail.com
My name is guoxin. 
Please view the English portion of the GOOGLE translation. 
Change PHP.ini configuration, as follows:

[MSSQL] 
; Allow or prevent persistent links. 
mssql.allow_persistent = On 

; Maximum number of persistent links.  -1 means no limit. 
mssql.max_persistent = -1 

; Maximum number of links (persistent+non persistent).  -1 means no limit. 
mssql.max_links = -1 

; Minimum error severity to display. 
mssql.min_error_severity = 1000 

; Minimum message severity to display. 
mssql.min_message_severity = 1000 

; Compatibility mode with old versions of PHP 3.0. 
mssql.compatability_mode = Off 

; Connect timeout 
mssql.connect_timeout = 5 

; Query timeout 
mssql.timeout = 60 

; Valid range 0 - 2147483647.  Default = 4096. 
;mssql.textlimit = 4096 

; Valid range 0 - 2147483647.  Default = 4096. 
;mssql.textsize = 4096 

; Limits the number of records in each batch.  0 = all records in one batch. 
;mssql.batchsize = 0 

; Specify how datetime and datetim4 columns are returned 
; On => Returns data converted to SQL server settings 
; Off => Returns values as YYYY-MM-DD hh:mm:ss 
;mssql.datetimeconvert = On 

; Use NT authentication when connecting to the server 
mssql.secure_connection = on 

; Specify max number of processes. -1 = library default 
; msdlib defaults to 25 
; FreeTDS defaults to 4096 
;mssql.max_procs = -1 

; Specify client character set. 
; If empty or not set the client charset from freetds.comf is used 
; This is only used when compiled with FreeTDS 
;mssql.charset = "ISO-8859-1"
 [2009-10-19 16:08 UTC] guoxinzz at 163 dot com
To correct a small error: 
mssql.connect_timeout = 60 

http://blog.csdn.net/gumanren


From mainland China
 [2010-07-18 16:57 UTC] opc dot three at gmail dot com
Related to Bug #29074
 [2010-12-28 13:27 UTC] shutzel at gmx dot de
I had the same problem with mssql_connect() Unable to connect to server. Type in the shell "php -m" and if you get an error that the "MSVCR71.dll" is missing, just download it from this address http://www.dlldump.com/download-dll-files.php/dllfiles/M/MSVCR71.dll/download.html and copy it to c:\windows\system32 - thats it!

Greetings from munich germany ;)
 [2010-12-28 13:44 UTC] pajoye@php.net
@shutzel at gmx dot de

Unrelated to this bug report, you simply have to install the MS SqlServer connection drivers, as usual :)
 [2011-02-22 08:40 UTC] satyanarayana at egbsystems dot com
i am using PHP Version 5.2.5 , xampp , mssql windows 2005.  i am not able to connect mssql server . it saying unable to connect
 [2011-07-28 03:31 UTC] DennisThen at yahoo dot com
I am using php 5.1.6 with apacher 2.2 and windows xp sp
how to config php.ini for me access sql server 2008 ?
 [2014-12-29 01:05 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: fmk +Assigned To:
 [2016-10-15 23:10 UTC] kalle@php.net
-Status: Open +Status: Wont fix
 [2016-10-15 23:10 UTC] kalle@php.net
With MSSQL being removed from PHP as of PHP7.0, and ext/mssql not having a maintainer, I'm gonna close this report as a Won't fix, until maybe one day it will find a new maintainer.

Alternatively you can use sqlsrv from Microsoft if you are on Windows, or pdo_dblib if you are on Unix.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 23:01:29 2024 UTC