简体   繁体   English

无法建立与 MS SQL Server 2008 的连接

[英]Can't Establish connection to MS SQL Server 2008

I have been trying to establish a connection to a SQL Server 2008 but i get a return message saying:我一直在尝试与 SQL Server 2008 建立连接,但收到一条返回消息:

Connection could not be established.无法建立连接。 Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => -1 [code] => -1 [2] => [Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. [message] => [Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired [message] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => -1 [code] => -1 [2] => [Microsoft][ODBC Driver 11 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. [message] => [Mic数组 ( [0] => 数组 ( [0] => 08001 [SQLSTATE] => 08001 [1] => -1 [代码] => -1 [2] => [Microsoft][ODBC Driver 11 for SQL Server ]SQL Server 网络接口:定位服务器/实例指定 [xFFFFFFFF] 时出错。[消息] => [Microsoft][SQL Server 的 ODBC 驱动程序 11]SQL Server 网络接口:定位服务器/实例指定的 [xFFFFFFFF] 时出错。) [1 ] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 11 for SQL Server]登录超时已过期[消息] => [Microsoft][ODBC Driver 11 for SQL Server]登录超时)[2] => Array ([0] => 08001 [SQLSTATE] => 08001 [1] => -1 [code] => - 1 [2] => [Microsoft][ODBC Driver 11 for SQL Server]与 SQL Server 建立连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。检查实例名称是否正确如果 SQL Server 配置为允许远程连接。有关详细信息,请参阅 SQL Server 联机丛书。[消息] => [麦克风rosoft][ODBC Driver 11 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. rosoft][ODBC Driver 11 for SQL Server]建立与 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.检查实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 For more information see SQL Server Books Online.有关详细信息,请参阅 SQL Server 联机丛书。 ) )

My PHP Code:我的 PHP 代码:

<?php
$serverName = "SERV002\SQLEXPRESS"; //serverName\instanceName
$connectionInfo = array( "Database"=>"YSHSDB", "UID"=>"sa", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>

UPDATE: I have fixed this by installing xampp lite onto my server 2003 running the SQL server however, I would still like to be able to access the SQL server if the web services is running on another machine.更新:我已经通过在运行 SQL 服务器的服务器 2003 上安装 xampp lite 解决了这个问题,但是,如果 Web 服务在另一台机器上运行,我仍然希望能够访问 SQL 服务器。

The obvious error here is that your SQL server is not running or is not configured to allow remote connections (I think that is the default for SqlExpress)这里明显的错误是您的 SQL 服务器未运行或未配置为允许远程连接(我认为这是 SqlExpress 的默认设置)

You will need to open your Sql Connection Manager and change the settings for TCP connections to make them available for remote connections.您将需要打开 Sql 连接管理器并更改 TCP 连接的设置以使其可用于远程连接。 You may also have a firewall blocking your Sql Connection somewhere.您可能还有防火墙在某处阻止了您的 Sql 连接。 Make sure port 1433 is exposed in any fire wall.确保端口 1433 暴露在任何防火墙中。

Open your Server Configuration Manager Server Configuration Manager打开您的服务器配置管理器服务器配置管理器

Under SQL Server Network Configuration Click on Protocols for SQLEXPRESS在 SQL Server 网络配置下单击SQLEXPRESS 的协议

Rightclick and access Properties of TCP/IP右键单击并访问 TCP/IP 的属性

Select the IP Addresses Tab选择IP 地址选项卡

Now configure all the TCP Port (s) to the port you are using in your connection string.现在将所有TCP 端口配置为您在连接字符串中使用的端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM