none
Connection fails with 'Login failed for user xxx' RRS feed

  • Question

  • I'm trying to set up a demo on my local machine showing how to use SQLSRV in PHP. To facilitate, I've added a new login and a user using that login, both named DemoUser, and given that user db_datareader, db_datawriter and db_ddladmin roles for the example data I'm using (which is the Chinook database).

    I also set SQL Server on the machine to use both Windows and SQL Server authentication and restarted the server.

    With all that done, I can log in in SSMS as this user, and I can create a connection from Visual FoxPro (my usual dev tool) successfully using the SQLStringConnect() function. However, when I attempt to connect from PHP with sqlsrv_connect(), I get an error.

    Here's the connection code:

      $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));
      }


    and here's what I see:

    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'.
            )
    
    )
    
    Any ideas what I'm missing?



    Wednesday, July 3, 2019 3:36 PM