php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47580 MSSQL: "Changed database context to" when connecting
Submitted: 2009-03-05 21:27 UTC Modified: 2013-02-18 00:33 UTC
Votes:77
Avg. Score:1.4 ± 1.0
Reproduced:7 of 13 (53.8%)
Same Version:-3 (-42.9%)
Same OS:-5 (-71.4%)
From: maxcamo at gmail dot com Assigned:
Status: No Feedback Package: MSSQL related
PHP Version: 5.2CVS-2009-03-05 (snap) OS: Win2003
Private report: No CVE-ID: None
 [2009-03-05 21:27 UTC] maxcamo at gmail dot com
Description:
------------
Hi,

with MSSQL 2005,Apache 2.2.11 and PHP 5.2.6 i get this error when i 
try to connect to the db

Changed database context to

The error raise up when I try to connect to the DB.

connections timeout are high

mssql.connect_timeout = 300
mssql.timeout = 300

It happen randomly, but more frequently when the site traffic si very 
high

Reproduce code:
---------------
$Maxtries=60;

$delayMin=50000;
$delayMax=100000;
$delay=rand($delayMin,$delayMax);
$log_filename="conn_failed.log";
$tries=1;

	$connDb = @mssql_connect($host, $user, $pwd));
	if ($connDb)
		mssql_select_db($db, $connDb);

while(!$connDb){
	
	if ($tries>=$Maxtries){
		//echo "Database failed to respond.";
		$fp = fopen($log_filename,"a+");
		fputs($fp, gmdate("M d Y H:i:s") . ": Errore Connessione \r\n");
		fclose($fp);
 		exit;
	}
	
	usleep($delay*$tries);
	$connDb = @mssql_connect($host, $user, $pwd));
	if ($connDb)
		mssql_select_db($db, $connDb);
	
	$tries++;
}

if ($tries>1){
		$fp = fopen($log_filename,"a+");
		fputs($fp, gmdate("M d Y H:i:s") . ":: Try:$tries :: ".$ServerName.":: ".mssql_get_last_message()." :: ". $pageName . "\r\n");
		fclose($fp);
}



Expected result:
----------------
Db Connection

Actual result:
--------------
Mar 05 2009 21:08:19:: Try:2 :: B-C2N1:: Il contesto di database ? 
stato sostituito con 'dbName'. :: /index.html
Mar 05 2009 21:08:20:: Try:8 :: B-C2N1:: Il contesto di database ? 
stato sostituito con 'dbName'. :: /page2.html
Mar 05 2009 21:09:26:: Try:6 :: B-C2N1:: Il contesto di database ? 
stato sostituito con 'dbName'. :: /page3.html







Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-08 14:30 UTC] kalle@php.net
This is an informal notice from dblib, Microsoft's TechNet have information about this here:
http://technet.microsoft.com/en-us/library/aa275768(SQL.80).aspx
 [2009-03-09 07:32 UTC] maxcamo at gmail dot com
ok but i can't connect to the db,

chaging the script like this
if ($connDb)
    mssql_select_db($db, $connDb);
else
    $lastmsg=mssql_get_last_message()

and...

fputs($fp, gmdate("M d Y H:i:s") . ":: Try:$tries :: 
".$ServerName."::
".$lastmsg." :: ". $pageName . "\r\n");

i dont' get any mssql errors, but i get the same problem

I see this error randomly, or on heavy load, i think
 [2009-03-25 16:51 UTC] maxcamo at gmail dot com
ok but i can't connect to the db,

chaging the script like this
if ($connDb)
    mssql_select_db($db, $connDb);
else
    $lastmsg=mssql_get_last_message()

and...

fputs($fp, gmdate("M d Y H:i:s") . ":: Try:$tries :: 
".$ServerName."::
".$lastmsg." :: ". $pageName . "\r\n");

i dont' get any mssql errors, but i get the same problem

I see this error randomly, or on heavy load, i think
 [2009-05-25 19:46 UTC] kalle@php.net
Have you tried to change the severity with mssql_min_message_severity? Error 5701 (Changed database context to) is at severity 10.
 [2009-06-02 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-06-13 13:16 UTC] maxcamo at gmail dot com
I've tried but i get the same problem

Can be related to mssql time_wait tcp/ip?

Thx

Massimo
 [2011-02-05 20:29 UTC] nkrsaxena at gmail dot com
I am facing this problem, making me nuts :-X
it shows mssql connection connected
mssql selectdb fine
but while running query says "Changed database context to" and script terminated
the same is working fine
1. On MSSQL ternimal
2. php5.1.6 

i tried different RPMS and manual installation with all dependencies but still 
no luck, even on Clean servers RHEL5
Please help...
 [2011-02-05 21:20 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2011-02-05 21:20 UTC] pajoye@php.net
If you can try it on linux/unix with 5.3, please try it. If not I would suggest to 
use sqlsrv (http://sqlsrvphp.codeplex.com/) instead on Windows (and php 5.3).
 [2011-04-30 15:48 UTC] bguaitanele at gmail dot com
I had this problem using php 5.2.6 and php 5.3. This happen with me because the mssql timeout in php configuration. 

this problem has 2 solutions:
The right solution: Refactory your query because your query is taking too long time to respond to php. Case your query is fast, the problem can be the database. In my case was an alter index running and 2 jobs.

The fast solution: increase the variable mssql.timeout in php.ini. I increased to 300s and my error stop. But, this is not recommended, because the connections in your application server will increase, More people will be hang the response of the server.

Weel, hope this help
 [2013-02-18 00:33 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 08 12:01:26 2024 UTC