Patrick Alexson
Patrick Alexson

Reputation: 153

IIS PHP connect to MSSQL using Windows Authentication

I'm new to PHP and have run into a rather simple yet annoying issue.

Here is the setup:

If the users navigate to http://iisservername/ and try to connect to the mssql server via the php scripts, they receive Login failed for user NT AUTHORITY\ANONYMOUS LOGON

My workaround has been to launch a cmd script on the IIS server that uses runas /profile /user:domain\user "c:\program files\internet explorer\iexplore.exe"

I create a runas line for each user in the cmd script and execute it.

Upon launch, it navigates to homepage, which is a keepalive.php script I made that opens a connect and then javascript refreshes the page every x amount of minute(s).

Surely there is a better way to do this, yes?

Upvotes: 3

Views: 7163

Answers (1)

Phil W
Phil W

Reputation: 549

If you use sqlsrv_connect and are using IIS's built in authentication it should be handled for you with nothing more then:

/* Specify the server and connection string attributes. */
$serverName = "(local)";
$connectionInfo = array("Database" => "AdventureWorks");
/* Connect using Windows Authentication. */
$conn = sqlsrv_connect($serverName, $connectionInfo);

(example from: http://msdn.microsoft.com/en-us/library/cc296205%28v=sql.90%29.aspx)

Upvotes: 3

Related Questions