Skip to content
Advertisement

General error: 20003 Adaptive Server connection timed out [20003] (severity 6)

Hi Following is error what I am getting:-

PDOException: SQLSTATE[HY000]: General error: 20003 Adaptive Server connection timed out [20003] (severity
 6) [(null)] in /var/www/html/web/vendor/laravel/framework/src/Illuminate/Database/Connection.php:335

I am trying to connect to MS-SQL-Server on windows from linux laravel 5.2 code snippet.

  1. There is firewall disable on windows machine.
  2. I am able to telnet on windows ip on ms sql default available port.
  3. I am not using free TDS, so this is not duplicate of TDS and even that question is not answered.
  4. centos 7, able to ping to IP. there is no connection issue.
  5. Running script from terminal, so no timeout issue must be come.

Before I was trying to fetch 5k records, I thot query is taking longer time but even I reduce a limit to 100 then also getting same error. My net connection is high speed and server hardware is highly configured.

I have tried all the solution given on below link and I am getting success but when my script runs facing above issue.

[https://blogs.msdn.microsoft.com/sql_protocols/2008/04/30/steps-to-troubleshoot-sql-connectivity-issues/][1]

My script run well locally. But facing issue when I promoted code to dev.

Advertisement

Answer

The problem seems to be related to the execution time for your query.

I was having this same issue and it was solved after I’ve changed the timeout settings at config/databases.php file.

Use the code below:

'options' => [
    PDO::ATTR_TIMEOUT => 300, // up to 5 minutes
],

The complete config should be:

'sqlsrv' => [
    'driver' => 'sqlsrv',
    'host' => env('DB_HOST', 'localhost'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'prefix' => '',
    'options' => [
        PDO::ATTR_TIMEOUT => 300,
    ],
],
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement