Solved

SQL Server 2008 PHP 5.5.7 Connection Windows Authentication Error

Posted on 2013-12-17
3
1,234 Views
Last Modified: 2014-01-29
I am trying to establish a connection to SQL Server 2008 using the code shown below.  I'm also showing below the error message returned.  It seems that windows authentication is not quite working properly as it is passing my PC name rather than my windows logon and password.  Obviously SQL Server will refuse this connection since there is no user like my PC Name.  My question is how do I make Windows Authentication work properly?  
--scroll down to see the other two scripts I've tried:
<?php
$serverName = "serverName, 1433"; 

// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"dbName");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>

Open in new window


Here is the error message I receive:
Connection could not be established.
Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456
 => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'LC\SSTEVENSWIN7PC$'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'LC\SSTEVENSWIN7PC$'. ) [1] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'LC\SSTEVENSWIN7PC$'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'LC\SSTEVENSWIN7PC$'. ) )


Script #2, connect with user name and password - user is set up in SQL Server as Windows Authentication
[code]
<?php
$serverName = "serverName, 1433"; 
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>

Open in new window


Error Message:
Connection could not be established.
Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456
 => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'LC\sstevensProd'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'LC\sstevensProd'. ) [1] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'LC\sstevensProd'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'LC\sstevensProd'. ) )

Gets the right user logon information, but connection still fails.

Script #3:  connect with user name and password, but user is set up for SQL Server Authentication
[code]
<?php
$serverName = "serverName, 1433"; 
$connectionInfo = array( "Database"=>"dbName", "UID"=>"uid", "PWD"=>"pwd");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>

Open in new window


No errors, connection established.
0
Comment
Question by:SueJStevens
3 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39725450
In another question that I can't find right now, someone else said they solved this problem by setting up 'impersonation'.  I don't really know what that means.  The normal PHP/IIS user will never have the permissions by itself.  It is intentionally limited.

In my few pages with SQL Server, I have just used SQL Authentication which only requires username and password.
0
 
LVL 9

Accepted Solution

by:
rinfo earned 500 total points
ID: 39726264
Have you checked
1.if sqlserver is configured to work in mixed authentication mode.
2.You are logged into correct windows domain properly.
3.It could be UAC make sure you are running as administrator
Besides this there is no reason why windows authentication would fail.
As long as servername and database name is proper.
0
 

Author Comment

by:SueJStevens
ID: 39818067
I'm not certain my issue is resolved, but closing it anyway.  I was not able to get windows authentication to work but I can get the admin account to work.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question