Answered Windows Authentication Failed

  • Monday, July 02, 2012 1:28 PM
     
     

    Hello, 

    I am on a Windows 7 x86. I am trying to authenticate my user to a remote SQL 2008 R2 database on a Windows Server 2008 R2 by Windows Authentication. I got this error :

    "Unable to connect.

    Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'DOMAIN\ComputerName$'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'DOMAIN\ComputerName$'. ) [1] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => (...)  "

    'DOMAIN' = my user's domain and ComputerName = my computer's name

    But when I log on with SQL Server management studio and Windows Authentication, it works perfectly.

    I have :

    - WAMP 2.2 with PHP 5.4 and Apache 2.2, 

    - SQL Server Driver for PHP v 3.0

    - SQL Server Native Client 2012 (I had an error who forced me to install it :-))

    Do you have any idea?

    Thanks! (I read a lot of articles here but nothing helped me to resolve my problem)


    Here is my code:

    /* Specify the server and connection string attributes. */
    $serverName = 'SQLSERVERNAME\PRE_XXXX';
    $connectionInfo = array( 'Database'=>'myDB');

    /* Connect using SQL Server Authentication. */
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    if( $conn === false )
    {
    echo "Unable to connect.</br>";
    die( print_r( sqlsrv_errors(), true));
    }

All Replies

  • Monday, July 02, 2012 5:32 PM
     
     Answered Has Code

    With Apache, the credentials used to log in to SQL Server using Windows credentials are the credentials used to launch the Apache service.

    When you open Management Studio, it runs with your own Windows account - the current interactive user.

    You can do any of these:

    1. Grant access to your computer's account "DOMAIN\computer$" on SQL Server
    2. Change the Windows ID used to launch service Apache2.2 from Local System to an account that has access to SQL Server  (don't forget the account still needs enough privileges to run the Apache httpd services).
    3. Log in using an SQL Server account (i.e. not a Windows account), and pass the user and password to sqlsrv_connect:
      $connectionInfo = array( 
          'Database'=>'myDB',
          'UID'=>'SQLServerAccount',
          'PWD'=>'SQLServerPassword');
      


    Rob

    • Marked As Answer by MarDr Tuesday, July 03, 2012 7:30 AM
    • Unmarked As Answer by MarDr Tuesday, July 03, 2012 7:31 AM
    • Marked As Answer by MarDr Tuesday, July 03, 2012 7:31 AM
    •  
  • Tuesday, July 03, 2012 7:31 AM
     
     

    Yeh! You are amazing! :-)

    I follow your idea so I went to my local services and I changed the user launchig the wampapache service from "SYSTEMLOCAL" to my user :-)

    And now it works.

    Thank you so much!