从 PHP 到 SQL Server 的连接失败,并显示"Login failed for user xxx"



我正在尝试在本地计算机上设置一个演示,以显示如何在PHP中使用SQLSRV。为了促进,我添加了一个新的登录名和一个用户,使用该登录名,均名为Demouser,并鉴于我正在使用的示例数据(这是Chinook Database(。>

我还将机器上的SQL Server设置为使用Windows和SQL Server身份验证并重新启动服务器。

完成所有完成的操作,我可以作为此用户登录SSMS,并且可以使用SQLSTRINGCONNECT((函数成功创建Visual FoxPro(我通常的Dev Tool(的连接。但是,当我尝试通过php与sqlsrv_connect((连接时,我会遇到一个错误。

这是连接代码:

  $hostname = "localhost";
  $username = 'DemoUser';
  $password = 'mYdemoUser';
  $database = 'chinook';
  $connectionInfo = array("Database"=>$database, "UID"=>$username, "PWD"=>$password, "CharacterSet"=>"UTF-8");
  $conn = sqlsrv_connect($hostname, $connectionInfo);
  if( $conn == false ) {
    echo "Connection could not be established.<br />";
    die( print_r( sqlsrv_errors(), true));
  }

这就是我看到的:

Connection could not be established.Array
(
    [0] => Array
        (
            [0] => 28000
            [SQLSTATE] => 28000
            [1] => 18456
            [code] => 18456
            [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'DemoUser'.
            [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'DemoUser'.
        )
    [1] => Array
        (
            [0] => 28000
            [SQLSTATE] => 28000
            [1] => 18456
            [code] => 18456
            [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'DemoUser'.
            [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'DemoUser'.
        )
)

有什么想法我缺少什么?

检查服务器日志以查看为什么登录失败。这可能是权限问题

使用SQL Design Studio登录该用户,并验证您实际上可以与已知的好客户端连接。

相关内容

最新更新