none
Connect SQL Server Windows Authentication on remote server

    Question

  • HI !
    I tell you my scenary:

    Server1 (Web):
    - Apache 2.2,
    - PHP 5.2
    - My web application.

    Server2 (DB):
    - SQL Server 2005 Express.
    - Allows remote connections.
    - Allow mixed authentication modes.

    I am trying to connect from web server to the database using Windows Authentication.

    The connection string using ODBC is:
    <?php 
    $data_source='Driver={SQL Server};Server=server_name\\SQLEXPRESS;Database=db_name;Trusted_Connection=yes;';
    $user='server_name\\user_name';
    $password='password';
    
    $conn=odbc_connect($data_source,$user,$password);
    ?>
    But throws the following error:
    Error de inicio de sesión del usuario 'NT AUTHORITY\ANONYMOUS LOGON'.


    The connection using SQL Server Driver for PHP (
    according this example: http://msdn.microsoft.com/en-us/library/cc296205(SQL.90).aspx):
    <?php
    $serverName = "server_name\\SQLEXPRESS"; 
    $database = "db_name";
    $uid='server_name\\user_name';
    $pwd='password';
    
    $connectionInfo = array( "Database"=>$database);
    
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    if( $conn === false )
       die( print_r( sqlsrv_errors(), true));
    ?>
    But throws the same error:
    [0] => Array
        (
          [0] => 28000
          [SQLSTATE] => 28000
          [1] => 18456
          [code] => 18456
          [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Error de inicio de sesión del usuario 'NT AUTHORITY\ANONYMOUS LOGON'.
          [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Error de inicio de sesión del usuario 'NT AUTHORITY\ANONYMOUS LOGON'.
        )


    Interesting:
    - I tried use SQL server logins and it works perfectly, but I dont need it.
    - Also I tried run the database in mode local with the web server, using this same code, and it WORKS. But I dont need it...

    I Tried also with mssql_connect function, but nothing works.

    I dont know if it is posible, but according documentation http://msdn.microsoft.com/en-us/library/cc296205(SQL.90).aspx it should be.

    Thanks for help.
    Sunday, June 27, 2010 12:52 AM

Answers

  • Are you running FastCGI in Apache? It doesn't support impersonation so you will need to run the service as an authorized user to the remote sql server. If you were running IIS, set fastcgi.impersonate = 1;

    Sunday, June 27, 2010 3:52 PM

All replies

  • Are you running FastCGI in Apache? It doesn't support impersonation so you will need to run the service as an authorized user to the remote sql server. If you were running IIS, set fastcgi.impersonate = 1;

    Sunday, June 27, 2010 3:52 PM
  • In fact, I had to run Apache service as an domain USER who be authorized in SQL Server. So, it WORKS and I dont have to put user and password data in DSN.

    It is solved. thanks you very much.

    PD: So, I am in doubt about if it is posible using local users, but it is only curiosity.

    Sunday, June 27, 2010 5:12 PM
  • Just try using SQL Server, FastCGI and impersonate switched on. Not going to work. You will get the dreaded System error 5.

    Tuesday, April 10, 2012 7:30 PM