0

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?

Zhorov
  • 28,486
  • 6
  • 27
  • 52
  • What version of SQL Server (not SSMS)? Ie what is the output of `select @@version`? Is there anything in the SQL Server Errorlog corresponding to these errors? – David Browne - Microsoft Nov 09 '20 at 14:22
  • @David The output off select @@ version is: 'Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows 10 Home 10.0 (Build 18362: )' and in the SQL Server Errorlog are no errors. – AppleWithQuestions Nov 09 '20 at 14:37
  • Hmmm. Apply the latest Cumulative Upldate and see if that helps: https://support.microsoft.com/en-us/help/4577194/cumulative-update-8-for-sql-server-2019 A list of all the builds is here: https://support.microsoft.com/en-us/help/4518398/kb4518398-sql-server-2019-build-versions – David Browne - Microsoft Nov 09 '20 at 14:42
  • @DavidBrowne-Microsoft I updated to the latest version but it didn't help. (I think a already had that version but was not sure so did the update.) – AppleWithQuestions Nov 09 '20 at 15:05
  • 1
    `localhost,85` Probably something that is not SQL Server is, thus the TDS error. Is your SQL Server really listening on port 85? Look in the SQL Errorlog to see the actual port number. – David Browne - Microsoft Nov 09 '20 at 16:07
  • @DavidBrowne-Microsoft I looked at the SQL port. I saw that TCP/IP wasn't enabled and it stood on TCP poort 1433. I changed private $host = 'localhost,85'; to private $host = 'localhost,1433';, enabled TCP/IP and it worked.So can you put your last comment as answer so I can accept it. – AppleWithQuestions Nov 10 '20 at 09:03

0 Answers0