It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
I've been trying all day to connect a simple PHP script to the SQL Server installed on my machine. I'm using IIS7.5 if that matters somehow.

I really don't get what I'm doing wrong, since every change leads to another error, and I can say I've had enough if it.

Can someone post a simple example of connecting SQL Server to PHP using Windows Authentication?

Also, where do I see the exact server name? In SQL Server Management Studio the name is ANGEL-G71G, but in SQL Server Configuration Manager the name is MSSQLSERVER.

This is the error that I get:

Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. ) [1] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'NT AUTHORITY\IUSR'. ) )

EDIT: God fucking dammit. 4 hours of messing around, doing crap and all that.

So I put all SQL Server features to auto freaking start on log in, enabled all connections through named pipes, tcp/ip and what else not... Still didn't work...

Restarted my lappy, and now it works... What the eeeeeffffffffffffffffffffff...
Post edited May 14, 2011 by KavazovAngel
I don't know how you've got it working doing that, but here's my view on what you seem to be doing.

Firstly the reason you see MSSQLSERVER in the configuration manager is because that's the name of the service it runs under (which I assume means you're using SQL Server 2000). I seem to remember the SQL Server 2000 configuration manager was to let you also configure other instances of SQL server installed on the same machine (you can run two copies side by side).

The reason that you're getting the authentication error is because you are not impersonating any other user, so it accesses the SQL server as whatever user the application pool is configured to use. There are a few options here. You could set up the application pool to run as a more powerful and specific user. This means that you could then grant that user a login on your SQL server. This is not best practice, but is commonly done anyway as it is easiest.

Alternatively in your data access code you could impersonate a different user (don't know how in PHP). This is better as it means that only some portions of your code have elevated priviledges.

Alternatively you could configure the server to use mixed mode authentication, and add a SQL login to your connection string.
Thanks for the post. You're probably right about the MSSQLSERVER part. Meaning the server name that I need to specify is either ANGEL-G71G or (local). Both work so I guess I'll use one of them.

I was really pissed of because I created the "NT AUTHORITY\IUSR" and gave him ownership rights, but it still didn't work for some reason. So I enabled all connection types, specifically named pipes and tcp/ip. It still didn't work. Enabled the SQL Server Browser and User Agent, and it still didn't work. Turned off all SQL Server services, and started them again, and it still didn't work.

Added the connection string Server: ANGEL-G71G into IIS. This could have been it, I have no idea.

Then I removed all previously created custom users for SQL Server, restarted the lappy, created the 'NT AUTHORITY\IUSR' and it worked.

I know this may not be the safest way, but I just need it to work for a presentation. For the security and actual realization of the project, I'll read more about SQL Server when I'll be doing that.