SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746
Asked Answered
S

5

5

I'm using PHP Laravel 7.4 on Ubuntu 20.04.and trying to get data from SQL server located in windows server on another cloud.

this method was tested on my PC (Windows) and it successfully got the data from the windows server(mentioned above), But on my ubuntu server I follow the documents ubuntu 20.04 PHP 7.4 https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15

I got this error:

SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746 (SQL: myquery) {"userId":94,"exception":"[object] (Illuminate\Database\QueryException(code: 08001): SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746 (SQL: myquery) at /var/www/web-api/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669)

I checked the logs in Microsoft SQL Server Management Studio and I notice this message appears every time I make a request from Ubuntu

"An TLS 1.2 connection request was received from a remote client application, but none of the cipher suites supported by the client application are supported by the server. The SSL connection request has failed."

Soiree answered 26/9, 2021 at 12:59 Comment(0)
K
7

Try these steps:

  1. Install sqsrv & pdo_sqlsrv extension & restart apache

  2. Update & comment the mentioned line bellow in config/database.php sqlsrv array

    'port' => env('DB_PORT', '1433'),

Final value of sqlsrv driver will be like this:

'sqlsrv' => [
            'driver' => 'sqlsrv',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', 'localhost'),
            // 'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
        ],
  1. Hit these 2 command in command line of the project directory

      composer dump-autoload
    
      php artisan config:clear
    
Kliber answered 7/6, 2022 at 11:21 Comment(0)
W
2

using docker with thecodingmachine/php 8.0, I solved this problem with editing /etc/ssl/openssl.cnf using configuration from https://github.com/microsoft/msphpsql/issues/1023#issuecomment-732947905

Waltman answered 4/1, 2022 at 9:25 Comment(0)
A
1

I hadn't enabled the TCP/IP protocol in the "Protocols for MSSQLSERVER" section of the SQL Server network configuration. After enabling it, everything ran smoothly.

Alysa answered 31/3, 2024 at 16:14 Comment(1)
how do you enabled it @doanthen?Conspire
C
1

Enable TCP/IP for SQL Server in order to connect MSSQL SERVER TO LARAVEL APPLICATION

-> Open SQL Server Configuration Manager

-> naviage to SQL Server network configuration

-> enable TCP/IP protocol

-> doubel click to open the properties and navigate to IP Address tab and goto IPALL section and fill TCP PORT as 1433

-> Goto SQL Server Serives in the Sql server configuration manager and restare the SQL Server (SQLEXPRESS) service

above method will resolve the issue that i faced on laravel. [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it. following is the database connection example to config the second database

        'local_sqlsrv' => [
            'driver'    =>  'sqlsrv',
            'url'       =>  env('DATABASE_URL'),
            'host'      =>  '192.168.2.50',    // IP ADDRESS OF YOUR MACHINE 
            'port'      =>  '1433',           // PORT
            'database'  =>  'inteldemo',     // DATABASE
            'username'  =>  'intel',        // user name on MSSQL SERVER
            'password'  =>  'demolaravel', // password on MSSQL SERVER
            'prefix'    =>  '',
            'charset'   => 'utf8',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix_indexes' => true,
            'strict' => false,
            'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'true'),
        ],

Conspire answered 15/7, 2024 at 16:8 Comment(0)
L
0

I think I have faced similar error when using mssql with laravel. I solved it by installing and enabling the mssql php extension on the machine. Maybe it will help.

Lecher answered 26/9, 2021 at 19:46 Comment(1)
I did as you mentioned above and I'm still facing the same error. However, I checked the logs in MSSQL and I notice this message appears every time I make a request from Ubuntu "An TLS 1.2 connection request was received from a remote client application, but none of the cipher suites supported by the client application are supported by the server. The SSL connection request has failed."Soiree

© 2022 - 2025 — McMap. All rights reserved.