Wolftousen
Wolftousen

Reputation: 147

SQL Server PHP IIS

Ok, i'm having some trouble setting up SQL Server 2005 with PHP 5.2.17 on IIS 6.0.

I've installed all the drivers and the native clients as directed and my phpinfo() output contains the sqlsrv and the proper settings for it.

But, when I try to connect using this command:

sqlsrv_connect("address,port", array("UID"=>"un", "PWD"=>"pw", "Database"=>"db"));

I get the following error output:

Array
(
    [0] => Array
        (
            [0] => IMSSP
            [SQLSTATE] => IMSSP
            [1] => -49
            [code] => -49
            [2] => This extension requires either the Microsoft SQL Server 2008
Native Client (SP1 or later) or the Microsoft SQL Server 2008 R2 Native Client O
DBC Driver to communicate with SQL Server.  Neither of those ODBC Drivers are cu
rrently installed. Access the following URL to download the Microsoft SQL Server
 2008 R2 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?Link
Id=163712
            [message] => This extension requires either the Microsoft SQL Server
 2008 Native Client (SP1 or later) or the Microsoft SQL Server 2008 R2 Native Cl
ient ODBC Driver to communicate with SQL Server.  Neither of those ODBC Drivers
are currently installed. Access the following URL to download the Microsoft SQL
Server 2008 R2 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink
/?LinkId=163712
        )

    [1] => Array
        (
            [0] => IM002
            [SQLSTATE] => IM002
            [1] => 0
            [code] => 0
            [2] => [Microsoft][ODBC Driver Manager] Data source name not found a
nd no default driver specified
            [message] => [Microsoft][ODBC Driver Manager] Data source name not f
ound and no default driver specified
        )

)

The sqlncli.dll is in the windows/system32 folder and php_sqlsrv_52_ts_vc6.dll is in the php extensions folder and set to load in the php.ini.

I'm not sure why it's saying it requires the extension, when phpinfo says the extension is loaded and i'm also not sure why it is giving the ODBC Driver Manager error.

Any insight would be greatly appreciated.

========================================

Update/Edit: I tried using the following to connect and it worked just fine:

odbc_connect("Driver={SQL Native Client};Server=servername;Database=db", "un", "pw");

Is there a setting I could be missing in php.ini that could be preventing sqlsrv_connect from working properly?

Upvotes: 3

Views: 4775

Answers (3)

Federico Giust
Federico Giust

Reputation: 1793

It seems that you are having the same problem I was having this week.

For me, it turned out to be a permission issue in the registry where the path to sqlncli.dll is stored.

I downloaded Process Monitor and followed the instructions on this post

http://www.iislogs.com/articles/processmonitorw3wp/

Then I saw the process w3wp.exe was getting access denied on this registry key

HKLM\Software\ODBC\ODBCINST.INI\SQL Native Client 10.0

I opened RegEdit and went to that key.

I did right click - > Permissions and added Network Service to the list and gave it Read permissions.

Recycled the app pool and it is now working!

Hope it helps!

Cheers, Fede

Upvotes: 0

Brian Swan
Brian Swan

Reputation: 66

The sqlncli.dll is the SQL Native Client 2005 Try installing sqlncli10.dll (which is SNAC 2008) and see if that works. You can download it here (about 2/3 down the page): http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c6c3e9ef-ba29-4a43-8d69-a2bed18fe73c

-Brian

Upvotes: 1

JMP
JMP

Reputation: 7834

It's possible that you don't have your SQL Server configured for mixed-mode authentication. In Enterprise Manager or Management Studio, go to server properties > Security and make sure to enable both SQL Server and Windows Authentication modes.

Upvotes: 0

Related Questions