PHP sqlsrv_connect to SQL Server:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误 [英] PHP sqlsrv_connect to SQL Server: A network-related or instance-specific error has occurred while establishing a connection to SQL Server

查看:67
本文介绍了PHP sqlsrv_connect to SQL Server:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 PHP 7.1 连接到 SQL Server.我从以下位置添加兼容的驱动程序:

I want to connect PHP 7.1 to SQL Server. I add compatible drivers from:

https://docs.microsoft.com/en-us/sql/connect/php/microsoft-php-driver-for-sql-server

    try {
        $serverName = "tcp:localhost,1433";
        $connectionOptions = array("Database" => "fc","Uid" => "sa", "PWD" => 
"Aa123456");
        $conn = sqlsrv_connect($serverName, $connectionOptions);
        if ($conn == false){
            die (print_r(sqlsrv_errors ()));}
    } catch (Exception $e) {
        echo("Error!");
    }

到我的 php.ini,我在 phpinfo() 中检查了它现在我在 Windows 10 上安装了 ODBC 13.1 并正确安装了 SQL Server 2016,并且可以通过 sql server management studio 使用sa"用户登录.但是当我尝试这段代码时:

to my php.ini and I checked that in phpinfo() Now I have ODBC 13.1 on my windows 10 and install SQL server 2016 correctly and can login with "sa" user via sql server management studio. but when I try this code:

我收到此错误:[Microsoft][ODBC Driver 13 for SQL Server]建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.检查实例名称是否正确以及 SQL Server 是否配置为允许远程连接.有关详细信息,请参阅 SQL Server 联机丛书.

I get this error: [Microsoft][ODBC Driver 13 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.

请帮忙寻找答案...谢谢!

Please help to find the answer... thank you!

推荐答案

当 MS SQL Server 实例设置不正确时,我收到此错误.

I get this error when MS SQL Server instance is not set correctly.

可能的解决方案:

您应该检查您的服务器网络配置.转到 SQL Server 配置管理器(或计算机管理\服务和应用程序\SQL Server 配置管理器),然后转到 SQL Server 网络配置,InstanceName"的协议.首先,必须启用 TCP/IP.然后打开 TCP\IP 的属性.在IP 地址"选项卡上,转到 IPAll.要使此脚本工作,TCP 动态端口"必须为空,并且TCP 端口"必须等于 1433(或其他端口).

You should check your server network configuration. Go to SQL Server Configuration Manager (or Computer Management\Services and Applications\SQL Server Configuration Manager), then go to SQL Server Network Configuration, Protocols for "InstanceName". First, TCP/IP must be enabled. Then open Properties for TCP\IP. On "IP Addresses" tab, go to IPAll. For this script to work "TCP Dynamic ports" must be empty, and "TCP Port" must equals to 1433 (or some other port).

注意:

如果SQL Server Browser 服务"正在运行,则无需端口号即可连接.

If "SQL Server Browser service" is running, you can connect without port number.

这篇关于PHP sqlsrv_connect to SQL Server:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆