2

I am trying to fetch a set of fields from a Database on MSSQL Database on SQL Server 2012. This is a remote server and I am trying the following piece of code.

//MSSQL Server for retrieving the Member name from Member ID:

//mssql.secure_connection = On
// Need to upload ntwdblib.dll from net

$myServer = "IPAddress/SQLExpress "; // host/instance_name
$myUser = "ID"; // username
$myPass = "pass"; // paasword
$myDB = "dbname"; // database name

// connection to the database
$dbhandle = mssql_connect($myServer, $myUser,$myPass)
or die("Couldn’t connect to SQL Server on $myServer"). mssql_get_last_message();

// select a database to work with
$selected = mssql_select_db("sportsclub", $dbhandle)
or die("Couldn’t open database $myDB");

echo "You are connected to the " . $myDB . " database on the " . $myServer . ".";

$query = "SELECT first_name, last_name";
$query .= "FROM members ";
$query .= "WHERE member_id='".$row['member_id']."'"; 
 // your database query
$result = mssql_query($query);
while($row = mssql_fetch_assoc($result))
{
echo "<td>" . $rows["first_name"] . $rows["last_name"] . "</td>";
}
// close the connection
mssql_close($dbhandle);




//Ended MSSQL Connection

It simply does not connect to the sql server. It gives the error: Couldn’t connect to SQL Server on IPAddress/SQLExpress

I tried checking all configurations like TCP/IP through SQL Server Config management.

Can someone please help?

Anan
  • 103
  • 2
  • 13
  • What about things like firewalls? – Marc B Aug 15 '13 at 19:40
  • I would start by verifying that telnet works `telnet IPAddress 1433`, or if you have changed the port try that port. – vee Aug 15 '13 at 19:46
  • Well, Firewall has allowed Remote connection n the SQL Server.... unless I have to add the subnet to the allowed set of networks separately – Anan Aug 15 '13 at 19:49

1 Answers1

0

Ensure remote connections over named pipes are enabled and make sure you're using a backslash before the instance name:

$myServer = "IPAddress\SQLExpress ";

If you'd like to enable connection over the default port (1433) this answer will help.

Community
  • 1
  • 1
Bryan
  • 17,112
  • 7
  • 57
  • 80
  • What did you find in configuration manager? Please post screenshots of your network protocol configurations so we can point you in the right direction. – Bryan Aug 15 '13 at 20:53
  • The configuration manager has TCP/IP Enabled. The IP address of the machine to which I have to connect remote is present as IP and TCP is 1433. – Anan Aug 15 '13 at 21:43
  • I tried through the command prompt and got the following: C:\>sqlcmd /E /S 130.65.144.80\MSSQLSERVER Sqlcmd: Error: Microsoft SQL Server Native Client 11.0:SQL Server Network Interfaces: Connection string is not valid [87].. Sqlcmd: Error: Microsoft SQL Server Native Client 11.0:Login timeout expired. Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : A network-related or in stance-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 i f SQL Server is configured to allow remote connections. – Anan Aug 15 '13 at 21:47
  • @Anan You mentioned a connection attempt to `130.65.144.80\MSSQLSERVER`, but your original question had an instance name of `SQLEXPRESS`. Which is correct? Screenshots of the information requested would be more helpful. – Bryan Aug 16 '13 at 01:48