SQLSRV - Server is not found or not accessible (v2022)

Hello,with my phpmaker v2022.12.4, I can fetch tables from database MS SQL Server (v15.0.2000.5) and generate an application.
But I’m not able to run my application.I’m getting that error message :
…\vendor\doctrine\dbal\src\Driver\API\SQLSrv\ExceptionConverter.php(67): An exception occurred in the driver:
SQLSTATE [08001, 258]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Dépassement du délai d’attente.
SQLSTATE [HYT00, 0]: [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired
SQLSTATE [08001, 258]: [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books OnlineBecause message says Server is not accessible, I’ll try with a simple script. See below.
Apache (2.4.46) and php (8.1.13), and I’m able to query database and display the result…

        $serverName = "xxxxx\yyy"; 
	$connInfo = array("Database"=>"zzzz", "UID"=>"zzzzz", "PWD"=>"zzzzz");
	$conn = sqlsrv_connect($serverName, $connInfo);
	if($conn){
		echo "Database connection established.<br />";
		$sql = "
			SELECT ACRONYM FROM LOCATION l WHERE ID = 1
		";
		$stmt = sqlsrv_query($conn,$sql);
		if($stmt === false) {
			die(print_r(sqlsrv_errors(), true) );
		}
		while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
			echo $row['ACRONYM']."<br />";
		}
		sqlsrv_free_stmt($stmt);
	}else{
		echo "Connection could not be established.<br />";
		die(print_r(sqlsrv_errors(), true));
	}

I can’t solve this problem, any idea ?
Thanks for you help.

sonc wrote:

SQLSTATE [08001, 258]: [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. > Check if instance name is correct and if SQL Server is configured to allow remote connections.

That probably means you have not provided the correct connection info for runtime PHP, or your database does not support remote connections.If your SQL server is remote, make sure you have enabled TCP/IP connection (not only named pipe) of your SQL server.

Hello,$serverName is DNS (same result with an IP) + instance name.
This entry is the same in my phpmaker database configuration as in my own code to query the db.
MS SQL accepts remote connection (own code is working)only way from phpmaker to sync the database is with this configuration in database tab :Database type : Microsoft SQL Server
Server : xxxxxxx\zzz
Port : 1433
Username : zzzzz
Password : zzzzz
Database : yyyyyy
Schema : dboThen generated config.php is :

"Databases" => [
        "DB" => ["id" => "DB", "type" => "MSSQL", "qs" => "[", "qe" => "]", "host" => "xxxxxxx\\zzz", "port" => "1433", "user" => "zzzzz", "password" => "zzzzz", "dbname" => "yyyyyy"]
    ]

Regarding php documentaion sqlsrv_connect and Using Connection String Keywords with SQL Server Native Client,In my own script,

if I change “UID” to “user” (like phpmaker connString), query database is no more possible.
Connection could not be established.
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -1 [code] => -1 [2] => Invalid option user was passed to sqlsrv_connect. [message] => Invalid option user was passed to sqlsrv_connect. ) )if I change “PWD” to “password” (like phpmaker connString), query database is no more possible.
Connection could not be established.
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -1 [code] => -1 [2] => Invalid option password was passed to sqlsrv_connect. [message] => Invalid option password was passed to sqlsrv_connect. ) )if I change “Database” to “dbname” (like phpmaker connString), query database is no more possible.
Connection could not be established.
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -1 [code] => -1 [2] => Invalid option dbname was passed to sqlsrv_connect. [message] => Invalid option dbname was passed to sqlsrv_connect. ) )Finally, parameter host isn’t correct too.
It must be changed with ServerConnString is becomming
“Databases” => [
“DB” => [“id” => “DB”, “type” => “MSSQL”, “qs” => “[”, “qe” => “]”, “Server” => “aaaaaaaa\bb”, “UID” => “cccccccc”, “PWD” => “ddddddd”, “Database” => “eeeeeeee”]
],
And it works !Now problem is that for each generation I had to update manually the config.production.php file.
Any idea ?

Your own script probably tries to include the config.php and create its own sqlsrv connection itself using the same connection info. You should note that PHPMaker uses DBAL which support different databases, not just SQL Server, so DBAL’s connection option names are “normalized”, read Connection Details.

If your scripts are Custom Files with Includes common files enabled, you should simply re-use PHPMaker functions such as ExecuteQuery(), no need to use sqlsrv functons, read Database Abstraction Layer.If your own scripts are standalone but try to include config.php, you do need to convert the connection info yourself.

This is mostly like due to the port number. In your custom script, you did not include the port number in your connection string. If you include it, I’m sure it will have problem connecting as well.Make sure you enabled TCP/IP in your SQL Server Configuration Manager and maybe fix the port instead of dynamic port number.