Can't connect to MSSQL using PHP on IIS

5.3k views Asked by At

I'm looking for solution for 2 days already. I'm getting following effect:

   array(2) {
  [0] => array(6) {
    [0] => string(5) "IMSSP"
    ["SQLSTATE"] => string(5) "IMSSP"
    [1] => int(-49)
    ["code"] => int(-49)
    [2] => string(390) "This extension requires either the Microsoft SQL Server 2008 Native Client (SP1 or later) or the Microsoft SQL Server 2008 R2 Native Client 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"
    ["message"] => string(390) "This extension requires either the Microsoft SQL Server 2008 Native Client (SP1 or later) or the Microsoft SQL Server 2008 R2 Native Client 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(6) {
    [0] => string(5) "IM002"
    ["SQLSTATE"] => string(5) "IM002"
    [1] => int(0)
    ["code"] => int(0)
    [2] => string(91) "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
    ["message"] => string(91) "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
  }
}

Looks like there's no "Microsoft SQL Server 2008 R2 Native Client" but there is!

I've already used same configuration on my local machine and test server. I was getting same error on local machine when there was no "Microsoft SQL Server 2008 R2 Native Client" installed. After installing it the problem was solved.

Unfortunatelly here I can't see any change.

I was trying different PHP and sqlsrv drivers but that had no effect.

I can't experinemt a lot because this is live server.

How can I make this working? Is this have something to do with control panel ODBC settings? There's also another native client installed but I can't remove it from this live server.

How to read this information? Does php sqlsrv driver sees native client at all?

Edit

The problem is that I'm using everything in 32 bit. Native driver is also shown in ODBC control panel. Sqlsrv extension for PHP is also working as shown in phpinfo.

How is that possible that sqlsrv extension for PHP doesn't "see" that native client?

I'm powerless and now I'm setting up VM where I'll set exactly the same cofiguration as on web server and will make some bolder experiments.

2

There are 2 answers

4
Sam On

Install 32 and 64 bit drivers on the server. The 32 bit odbc control panel is located in the Windows\SysWow64 directory - not totally obvious, but that's it. Make sure you have drivers for your executable (PHP) - if it's 32 bit, you need 32 bit drivers.

1
Federico Giust On

It seems that you are having the same issue as I was having this week

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