com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 172.xx.xx.x, port 1433 has failed.
Error : Connection refused: connect. Verify the connection properties.
Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port.
Make sure that TCP connections to the port are not blocked by a firewall.
Code
<?php
try {
$conn = new PDO("sqlsrv:server=172.xx.xx.x;Database=mydb;", "username", "password",
array(PDO::ATTR_PERSISTENT => true) );
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "<h1>Connection established</h1>";
} catch (PDOException $e) {
$error_message = $e->getMessage();
echo "<h1>Connection could not be established.</h1>";
echo "<b>Error : </b> ". $error_message;
}
?>