2011-02-04 62 views
3

好的,我在使用PHP 5.2.17在IIS 6.0上设置SQL Server 2005时遇到了一些麻烦。SQL Server PHP IIS

我已按照指示安装了所有驱动程序和本机客户端,并且我的phpinfo()输出包含sqlsrv及其适当的设置。

但是,当我尝试使用这个命令连接:

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

我碰到下面的错误输出:

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 
     ) 

) 

的sqlncli.dll是在windows/system32文件夹下,并php_sqlsrv_52_ts_vc6。 dll在php extensions文件夹中,并设置为在php.ini中加载。

我不知道为什么它说它需要扩展,当phpinfo说扩展已加载,我也不知道它为什么会给ODBC驱动程序管理器错误。

任何有识之士将不胜感激。

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

更新/编辑: 我试着用下面的连接和它的工作只是罚款:

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

是否有设置我可以在php.ini可能会阻碍sqlsrv_connect的正常工作会丢失?

回答

0

您可能没有将SQL Server配置为混合模式身份验证。在Enterprise Manager或Management Studio中,转至服务器属性>安全性,并确保启用SQL Server和Windows身份验证模式。

+0

这确实是一个常见问题。 – zanlok 2011-02-04 18:27:59

+0

混合模式被启用,我再次检查管理工具中的数据源,sql server和sql本地客户端都在那里。 – Wolftousen 2011-02-04 19:32:39

0

看来,你有我这个星期有同样的问题。

对我来说,原来是存储sqlncli.dll路径的注册表中的权限问题。

我对这个职位下载Process Monitor,然后按照说明

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

然后我看到了过程的w3wp.exe是越来越访问被拒绝在此注册表项

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

我打开RegEdit并转到该密钥。

我做了右键单击 - >权限,并将网络服务添加到列表,并给它读取权限。

回收应用程序池,它现在工作!

希望它有帮助!

干杯, Fede