Solved

SQL Server 2008 PHP 5.5.7 Connection Windows Authentication Error

Posted on 2013-12-17
3
1,252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

724 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