October 22, 2024
Chicago 12, Melborne City, USA
PHP

Connect PHP to Microsoft SQL Server


I want to connect my domain website to an Microsoft SQL Server. I have done this before and it worked well. Im trying now with another SQL Server and it returns "A network-related or instance-specific error has occurred while establishing a connection".
I’ve done all firewall stuff to allow that port, telnet cmd works fine, i can enter in that SQL in my computer, so i think the configuration to accept remote connection is okay.
Here is my php:

$serverName = "DYNDNS,49550"; 
$database = "db22";
$uid = "sa"; // Usuário
$pwd = "********"; // Senha

$connectionOptions = array(
    "Database" => $database,
    "Uid" => $uid,
    "PWD" => $pwd,
    "Encrypt" => false 
);

$conn = sqlsrv_connect($serverName, $connectionOptions);

if ($conn === false) {
    handleError(sqlsrv_errors());
    exit;
}

function handleError($errors) {
    foreach ($errors as $error) {
        echo "Erro: {$error['message']} (Código: {$error['code']})<br />";
    }
}

The previous microsoft sql connection i did was always returning errors, i then found "Encrypt"=>false and it worked fine. This one won’t work either way.


Erro: [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired (Código: 0)
Erro: [Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: Error code 0x2749 (Código: 10057)
Erro: [Microsoft][ODBC Driver 18 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to dyndns….,49550. 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. (Código: 10057)

Connecting to a microsoft sql server remotely



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video