PHP trying to login to MSSQL (windows authentication) with computer name instead of login name

时间秒杀一切 提交于 2019-12-21 20:25:03

问题


I am trying to establish a connection to my company's MSSQL server with windows authentication , but it fails as it is trying to use my computer name as login instead of my login id. When logging in with the MS SQL Server Management the windows authentication works fine, but not with this PHP code:

<?php
// Server in the this format: <computer>\<instance name> or 
// <server>,<port> when using a non default port number
$serverName = "xxx";
$connectionInfo = array( "Database"=>"xxx");

/* Connect using Windows Authentication. */
$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));
}

// 
?>

The printout I get is the following:

[Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'xxx\T2002197$'. ) )

T2002197 is my computer name, not my login id, so of course it fails. How can I solve this? I am using WAMP. Edited out some info, replaced with 'xxx'


回答1:


Aah problem solved! I changed the settings on my WAMP service (open service.msc in Windows) and made sure the service logged on the correct account. It works now.




回答2:


The manual says that per default the connection is using Windows Authentication and not the SQL Server authentication.

To bypass this you need to provide the uid and pwd options in your $connectionInfo data.

Se the manuals;

http://php.net/sqlsrv_connect

http://msdn.microsoft.com/en-us/library/ff628167.aspx



来源:https://stackoverflow.com/questions/13720237/php-trying-to-login-to-mssql-windows-authentication-with-computer-name-instead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!