I have a error named:
Connection error: SQLSTATE[HY000]: [Microsoft][ODBC Driver 17 for SQL Server] Protocol error in TDS stream.
I curently have this error for a week and decided to ask here for help.
Just for a bit off information I use:
- Internet Information Services (IIS) Manager (Version: 10.0.18362.1)
- Microsoft SQL Server Managment Studio (MS SSMS)(Version: 18.7.1)
- PHP (Version: 7.4.1)
- Windows 10
My code is:
// DatabaseConection.php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class Database{
// variabelen om contact met de database te maken
private $host = 'localhost,85'; // localhost port 85
private $dbName = 'Image_Database';
private $username = ''; // empty for security
private $password = ''; // empty for security
// variabel om connectie te leggen
private $conn;
public function dbConnectie(){
$this->conn = null;
try{
$this->conn = new PDO('sqlsrv:Server='.$this->host.';Database='.$this->dbName, $this->username, $this->password);
} catch (PDOException $exception){
echo 'Connection error: ' . $exception->getMessage();
}
return $this->conn;
}
}
$database = new Database;
$conn = $database->dbConnectie();
if($conn){
echo "Connection.";
}elseif(!$conn){
echo "Failed connection.";
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_close($conn);
I attempted to change the host but it didn't work.
How I attempted to change it + result:
private $host = 'localhost:85' -> Connection error: SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53].
private $host = 'localhost, 85' -> Connection error: SQLSTATE[HY000]: [Microsoft][ODBC Driver 17 for SQL Server]Protocol error in TDS stream
private $host = 'localhost', '85' -> HTTP ERROR 500
private $host = 'localhost', 85 -> HTTP ERROR 500
private $host = 'localhost,', 85 -> HTTP ERROR 500
private $host = 'localhost,', '85' -> HTTP ERROR 500
private $host = 'localhost,'. '85' -> Connection error: SQLSTATE[HY000]: [Microsoft][ODBC Driver 17 for SQL Server]Protocol error in TDS stream
private $host = 'localhost,85' -> Connection error: SQLSTATE[HY000]: [Microsoft][ODBC Driver 17 for SQL Server]Protocol error in TDS stream
private $host = '192.168.178.17,85' -> Connection error: SQLSTATE[HY000]: [Microsoft][ODBC Driver 17 for SQL Server]Protocol error in TDS stream
private $host = 'my laptop name (not placing here),85' -> Connection error: SQLSTATE[HY000]: [Microsoft][ODBC Driver 17 for SQL Server]Protocol error in TDS stream
At last I want to place my file structure to see if there is something wrong.
C:\inetpub\wwwroot2\classe\DatabaseConection.php
My question: Why do I get this error and how to get rid of it?