Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem conection with SQL server 2005

Status
Not open for further replies.

raai

Programmer
Jul 17, 2008
30
MX
Hi,

I have an application and i use SQL server 2005.
The problem is I login and I use the application but after X minutes display error:

PHP Exception(0): Error en la conexion a SQL Server. in C:\wamp\ at line 164

The XXX are folder of the proyect.

I use sqlsrv to control the database.

The lines to connect are:

PHP:
public function connect($auth) {
		try  {
			$connectionInfo = array(
				'Database' => $auth->database, 
				'UID'      => $auth->user, 
				'PWD'      => $auth->password
			);
			if ( ! $this->_con = sqlsrv_connect($auth->server, $connectionInfo) ) {
				throw new Exception('Error en la conexion a SQL Server.');
			}
			return $this->_con;
		} catch (Exception $e) {
			echo 'PHP Exception('
				. $e->getCode() . '): '
				. $e->getMessage() . ' in '
				. $e->getFile() . ' at line '
				. $e->getLine();
			exit();
		}
	}

Please tell me what is the problem

Thank's
 
The connection cannot be established at some point. This is more likely an intermittent connectivity issue in your network than a PHP issue, as it appears from your post that its connecting fine sometimes but then issues the error other times.

You can query the connection for more information about the connection:

Code:
[b][COLOR=#0000FF]if[/color][/b] [COLOR=#990000]([/color] [COLOR=#990000]![/color] [COLOR=#009900]$this[/color][COLOR=#990000]->[/color]_con [COLOR=#990000]=[/color] [b][COLOR=#000000]sqlsrv_connect[/color][/b][COLOR=#990000]([/color][COLOR=#009900]$auth[/color][COLOR=#990000]->[/color]server[COLOR=#990000],[/color] [COLOR=#009900]$connectionInfo[/color][COLOR=#990000])[/color] [COLOR=#990000])[/color] [COLOR=#FF0000]{[/color]
[tab][tab][tab][tab]throw [b][COLOR=#0000FF]new[/color][/b] [b][COLOR=#000000]Exception[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]'Error en la conexion a SQL Server: '[/color] [COLOR=#990000].[/color] [b][COLOR=#000000]print_r[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]sqlsrv_errors[/color][/b][COLOR=#990000](),[/color][COLOR=#993399]1[/color][COLOR=#990000]));[/color]
[tab][tab][tab][COLOR=#FF0000]}[/color]

This should tell you more about what is going on with the connection when it fails.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Hi vacunita,

The app generates the following errors:

HTML:
Array
(
    [0] => Array
        (
            [0] => IMSSP
            [SQLSTATE] => IMSSP
            [1] => -55
            [code] => -55
            [2] => Failed to retrieve the server version.  Unable to continue.
            [message] => Failed to retrieve the server version.  Unable to continue.
        )

)

I modified muy code add lines

PHP:
public function connect($auth) {
		try  {
			$connectionInfo = array(
				'Database' => $auth->database, 
				'UID'      => $auth->user, 
				'PWD'      => $auth->password
			);
			sqlsrv_configure("WarningsReturnAsErrors", 0); // new line add
			sqlsrv_configure("LogSubsystems", 0); // new line add
			if ( ! $this->_con = sqlsrv_connect($auth->server, $connectionInfo) ) {
				throw new Exception('Error en la conexion a SQL Server.');
			}
			return $this->_con;
		} catch (Exception $e) {
			echo 'PHP Exception('
				. $e->getCode() . '): '
				. $e->getMessage() . ' in '
				. $e->getFile() . ' at line '
				. $e->getLine();
				echo '<pre>'; print_r(sqlsrv_errors()); echo '</pre>';
				
			exit();
		}
	}

 
Its a strange error. All I can find is a few mentions of extremely large integers being defined before calling the connection function.


Not sure if it applies to your scenario.

Can't seem to find anything else other than some Bug reports dealing with that same integer issue.

Maybe someone else can chime in with some suggestions.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
do you get the same errors using PDO? If you haven't tried an alternative extension it's time to do that now in order to rule out the C bindings.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top