Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server 2008 PHP 5.5.7 Connection Windows Authentication Error

Posted on 2013-12-17
3
Medium Priority
?
1,298 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 84

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 1000 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
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 …
Suggested Courses

876 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