2012-11-25 130 views
1

任何一個可以解釋從下面的參數連接字符串:遠程SQL Server連接到PHP

server IP : 192.168.137.4 
Windows Authentication : Windows Authentication 
UserName : DELL-M102Z\dell 
Database : DataProd 
Network Protocol : <default> 
Product Name : Microsoft SQL Server Express Edition 
Server Name : DELL-M102Z\SQLEXPRESS 
Instance Name : SQLEXPRESS 
Computer Name : DELL-M102Z 

我想:

$serverName = "DELL-M102Z\SQLEXPRESS"; //serverName\instanceName 
$username = "DELL-M102Z\dell"; //serverName\instanceName 
$conn = mssql_connect($serverName,$username,''); 

...但我得到的結果是:

警告:mssql_connect()[function.mssql-connect]:無法連接到服務器:第17行的C:... \ index.php中的DELL-M102Z \ SQLEXPRESS 連接無法建立。

有誰能告訴我這裏有什麼問題嗎?

+0

用途是'DELL-M102Z'或'192.168.137.4'作爲服務器名enbaled。而用戶只需'dell'(如果*是具有訪問服務器權限的用戶)。 – PeeHaa

+0

由SQL管理工作室在SQL服務器上,我只能通過使用服務器名稱作爲localhost連接,但使用192.168.137.4時失敗,所以我應該怎麼做從遠程客戶端連接? – kreamik

+0

@ kreamik:請參閱數據庫服務器軟件的文檔,瞭解如何允許遠程連接它。正如錯誤所述,您有連接問題,這可能是防火牆或服務器配置以及其他許多事情。如有疑問,請聯繫系統管理員。如果您自己管理它,請檢查數據庫和服務器軟件的支持資源。 – hakre

回答

2

試圖按照此步驟: http://michaelellerbeck.com/2010/03/31/cant-connect-remotely-to-sql-server-2008/ 我知道我錯過了啓動SQL瀏覽器服務,這就是爲什麼我不能用遙控IP連接,

我從該網站的結論,我必須確保:

1. make sure you have allow network connection from sql server configuration tool 
2. allow connection for this port in firewall 
3. activate sql browser service 
4. make sure port is listen as the the service provide 

我得到了3號的問題,卻困了,這個網站解決問題: http://www.wikihow.com/Enable-Remote-Connections-SQL-2008-Express

1
<?php 
$myServer = 'xxx.xxx.xxx.xxx:yyyy'; 
$myUser = 'sa'; 
$myPass = 'xxxxx'; 

$con = mssql_connect($myServer, $myUser, $myPass) or die("Could not connect to database: ".mssql_get_last_message()); 
if($con){ 
echo "connected"; 
} 
// Select a database: 
mssql_select_db('new') 
    or die('Could not select a database.'); 

// Example query: (TOP 10 equal LIMIT 0,10 in MySQL) 
$SQL = "SELECT TOP 10 * FROM Table"; 

// Execute query: 
$result = mssql_query($SQL) 
    or die('A error occured: ' . mysql_error()); 

// Get result count: 
$count = mssql_num_rows($result); 
print "Showing $count rows:<hr/>\n\n"; 

// Fetch rows: 
while ($Row = mssql_fetch_assoc($result)) { 

    print $Row['BillNo'] . "\n"; 

} 

mssql_close($con); 

$ myServer ='IP_Address:PORT';

這裏分號是需要IP地址和端口 和 Mssql中在您的cPanel