naif basalib
naif basalib

Reputation: 71

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

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."

Upvotes: 5

Views: 30629

Answers (5)

Mohamed Raza
Mohamed Raza

Reputation: 983

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'),
        ],

Upvotes: 1

doanthean
doanthean

Reputation: 11

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.

Upvotes: 1

MD TAREK HOSSEN
MD TAREK HOSSEN

Reputation: 439

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
    

Upvotes: 7

Gigih Aji Ibrahim
Gigih Aji Ibrahim

Reputation: 405

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

Upvotes: 2

Rudolf
Rudolf

Reputation: 48

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.

Upvotes: 0

Related Questions