42000 [SQLSTATE] [Microsoft] [ODBC 17 驱动程序 SQL Server] [SQL Server] 无法打开数据库"



我正在使用SqlServer 2019和Php,我正在尝试连接到我的数据库,但我遇到了以下错误:

42000[SQLSTATE]=>42000[1]=>4060[代码]=>4060[2]=>[Microsoft][ODBC 17 SQL Server驱动程序][SQL Server]它不是可以打开数据库""登录名"请求。登录失败。[message]=>[Microsoft][ODBC Driver 17 for SQL Server][SQL服务器]无法打开数据库""登录时请求。登录失败。(

我连接到数据库的代码是:

try{  
$dbName = "GestonePreventiviDB";
$serverName = "localhost";  //serverNameinstanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>$dbName);
$conn = sqlsrv_connect( $serverName, $connectionInfo,);
if( $conn ) {
echo "Conessione effettuata <br />";
}else{
echo "Impossibile stabilire una connessione.<br />";
die( print_r( sqlsrv_errors(), true));
}
}
catch (PDOException $e) {
echo "Errore connessione<br>".$e->getMessage();
} catch (Exception $e) {
echo "General Error: errore<br>".$e->getMessage();
}

在我创建数据库的Pc上,它可以工作,但当我试图在桌面上复制时,我遇到了错误。有人能帮我吗?

尝试更改行:

$conn = sqlsrv_connect( $serverName, $connectionInfo,);

进入:

$conn = sqlsrv_connect($serverName, $connectionInfo);

结尾没有逗号。

最新更新