我有一个用PHP 7.2和SQL Server 2019开发的应用程序。该应用程序托管在IIS 10上。我能够使用db的用户名和密码在应用程序和数据库之间建立连接。但是现在我的客户希望我们使用Windows身份验证来访问数据库。他们给了我们一个服务名称和一个实例名称,
用于测试连接的代码是
<?php
$serverName = "DEV1ECLD001A\FEB19M"; //serverName\instanceName
$connectionInfo = array( "Database"=>"ECLIPSE");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
try {
if( $conn ) {
echo "Connection established.<br />";
}else{
//throw new Exception('Unable to connect');
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
}catch(Exception $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
?>
``````````
In php.ini, added the lines below
fastcgi.impersonate = 0
mssql.secure_connection = On
In IIS sever,
Anonymous Authentication = Disabled
Windows Authentication = Enabled
My DB and UI are in 2 different servers and I am able to ping both and access the DB if username and password are given but not through windows auth.
While trying to connect, get this error below:
Connection Could not be established. Login failed for user prod/DEV1ECLD001A$
Am I overlooking something ? Kindly help to resolve.
答案 0 :(得分:0)
您需要:
警告,如果使用IIS Windows身份验证,则连接的用户需要使用数据库的权限。
要检查配置是否正确,由IIS启动的Windows任务管理器中为PHP-CGI.exe启动的帐户必须与应用程序池的身份配置中定义的帐户相同。