msphpsql: sqlsrv_connect does not try to establish a connection when there is no instance specified
PHP version: 8.3.8 PHP SQLSRV or PDO_SQLSRV version 5.12.0 Microsoft ODBC Driver version 18.3.3.1-1 Client operating system Fedora Linux
Problem description
I am trying to connect to an SQL-Endpoint of a DataWarehouse / -Lakehouse which is running inside of Microsoft Fabric. The connection works as expected when using DBeaver (which uses JDBC internally) and also with sqlcmd.
$ sqlcmd -S [warehouse-id].datawarehouse.fabric.microsoft.com -U '[my-username]' -G
When I try to establish the same connection with sqlsrv_connect in PHP, I get the following behavior:
$serverName = '[warehouse-id].datawarehouse.fabric.microsoft.com';
$user = "[my-username]";
$pwd = "[my-pwd]";
$connectionOptions = [
"Authentication" => "ActiveDirectoryPassword",
"UID" => $user,
"PWD" => $pwd,
];
$conn = sqlsrv_connect($serverName, $connectionOptions);
var_dump($conn); // will be false
var_dump(sqlsrv_errors()); // will be null
This fails almost instantly and without any hint of the possible error. I enabled logging for SQLSRV and all I get is sqlsrv_connect: entering and immediately after that the var_dump($conn) returning false.
By now, I’ve found out that as soon as I add an instancename, like:
$serverName = '[warehouse-id].datawarehouse.fabric.microsoft.com/MSSQLSERVER';
the command will try to connect for ~15 seconds and then fail with one of these two errors:
TCP Provider: Error code 0x2AF9MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF]
Since I don’t know the instance name (if there is one) this doesn’t really help me that much.
Expected behavior and actual behavior
I expect the sqlsrv_connect command to at least try to connect to the given server URL, even when there is no instance specified. Furthermore I would expect some kind of error message detailing why the function returned false.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17 (8 by maintainers)
Great! In retrospect it makes sense, since data warehouse doesn’t support MARS and it’s on by default in PHP driver. But the lack of a clear error makes it difficult to figure out. I will be looking at the docs to add this for sure, as this is a very unintuitive issue otherwise.