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

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.
There is firewall disable on windows machine.
I am able to telnet on windows ip on ms sql default available port.
I am not using free TDS, so this is not duplicate of TDS and even that question is not answered.
centos 7, able to ping to IP. there is no connection issue.
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.

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

Related

Remote Connection to Mysql Server From Laravel Application

I am trying to connect a laravel application to a remote database.The connection works successfully on my local machine but does not work in the production environment.The laravel application is connected to its own database hosted in the cloud but i want to access another database hosted by another provider.Hence,I did the following:
In Config/database file in laravel folder,I added another mysql connection
config the .env file as well.
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'mysql3' => [
'driver' => 'mysql',
'host' => env('DB_HOST_THIRD','localhost'),
'port' => env('DB_PORT_THIRD'),
'database' => env('DB_DATABASE_THIRD',''),
'username' => env('DB_USERNAME_THIRD',''),
'password' => env('DB_PASSWORD_THIRD',''),
],
Then in .env file:
DB_CONNECTION=mysql3
DB_HOST_THIRD=remote IP
DB_PORT_THIRD=3306
DB_DATABASE_THIRD=Remote DB Name
DB_USERNAME_THIRD=Username
DB_PASSWORD_THIRD=password
With the above setting, i can connect to the remote database successfully on my local machine.
Upon deployment, I am unable to connect to this remote database,even though a designated user has been created and access granted through the control panel.This remote database is hosted by GoDaddy and i have called but they said nothing is blocking my application, that everything is ok from their end. Below are what I have done:
I am able to connect the remote Database using Sqlyog, Mysql client successfully.
I connected to Terminal on the Remote Cpanel and try to grant all access to the User at its IP but the response is: "Access denied for user 'username#Remote IP'(using password:YES)".
From web application, the error is : "SQLSTATE[HY000] [2002] Connection refused".
I have telnet the remote IP with port 3306, which respond well. Please, can someone help me, perhaps there are things i am missing or is this kind of issue peculiar to Godaddy shared hosting?. I have checked the following from Stackoverflow:
Enable remote MySQL connection: ERROR 1045 (28000): Access denied for user

Laravel / MySQL Error: SQLSTATE[HY000]: General error: 1835 Malformed communication packet

Good morning. I'm using Laravel on VPS server.
Short situation description: Yesterday everything was working fine (for months our website were working fine), this morning I got woke up from my colleagues that both of our websites are down.
When trying to access them we receive error:
SQLSTATE[HY000]: General error: 1835 Malformed communication packet (SQL: select * from users where id = 1 limit 1)
I have checked online and can't find a solution. I tried to upgrade MySQL to newest version (Maria DB 10.3)
I tried to reset password for database user. (Also no changes)
I checked and tried sollution to set read_rnd_buffer_size=256K in my.cnf file for mysql settings
When I try to call this function directly in phpMyAdmin select * from users where id = 1 limit 1 it returns expected results.
I will appreciate every help, as all of our business depends on these platforms, I need to make them work as soon as possible.
With greetings, Artis.
Edit:
When I try to disable function that causes error, it just shows next function, and all over like that. So I believe that Laravel can't conect with mysql at all.
After deeper research I found out that only Laravel can't connect to database. On same server I have 2x Laravel applications, Codeigniter and wordpress. Both Laravel applications stopped to work at same time, but codeigniter and wordpress works as expected.
for a quick fix just add this
'options' => [PDO::ATTR_EMULATE_PREPARES => true]
to config/database.php in
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
'options' => [PDO::ATTR_EMULATE_PREPARES => true],
],
the proper solution is to upgrade your php from 7.2 to 7.4 or downgrade your mariadb
The new update requires PHP 7.3 to connect with MariaDB.
Since the issue is caused by the latest upgrade from MariaDB MDEV-24121, a more suitable solution is to downgrade MariaDB and yum-locking the MariaDB packages in place to avoid the packages from being updated and unlock them when they're patched. More details here on how to do it: Updating MariaDB to v10.2.35 or v10.3.26, causes MySQL Databases interface to show MySQL as offline
If you cannot downgrade your MariaDB or cannot update your PHP, a possible workaround is to set "PDO::ATTR_EMULATE_PREPARES" to true.

Laravel app hosted on Heroku with a Amazon RDS MySQL Database results in a connection time out

I have a Heroku app where I'm hosting my Laravel app. I started the development initially with MySQL, so I wanted to continue doing so using Amazon's RDS service. I create the instance there and managed to successfully connect via my MySQL client, the console etc.
The problem is that the Laravel app can't connect the database after numerous desperate attempts for me to fix it. I have found some articles suggesting the use of DATABASE_URL environment variable is mandatory, so I added it via the Heroku app settings. It looks like so:
mysql://myusername:mypass#myhostnamefromamazon/mydb?sslca=/app/storage/certs/amazon-rds-ca-cert.pem
I found this solution on Heroku's website. I have placed the amazon-rds-ca-cert.pem file on my Laravel's storage folder, like so: /app/storage/certs/amazon-rds-ca-cert.pem
This didn't solve my issue, so then I kept looking and found a Stackoverflow question which had this issue on Lumen. I adjusted my config/database.php according to the answer, but it's still not working for me!
<?php
$credentials = get_db_credentials();
$config = [
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', $credentials->host),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', $credentials->database),
'username' => env('DB_USERNAME', $credentials->username),
'password' => env('DB_PASSWORD', $credentials->password),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
],
];
if (env('APP_ENV') == 'production') {
$config['connections']['mysql']['options'] = [PDO::MYSQL_ATTR_SSL_CA => '../storage/certs/amazon-rds-ca-cert.pem'];
}
return $config;
The get_db_credentials() function simply parses the DATABASE_URL environment variable.
The exact exception that I get is:
[2018-10-25 19:32:16] production.ERROR: SQLSTATE[HY000] [2002] Connection timed out {"exception":"[object] (Doctrine\\DBAL\\Driver\\PDOException(code: 2002): SQLSTATE[HY000] [2002] Connection timed out at /tmp/build_05920c42a6de0a378402b798320d3f04/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:50
I'm totally lost on this and unsure how to proceed.
Your AWS Security Groups must permit traffic from Heroku's IP address range.
https://devcenter.heroku.com/articles/amazon-rds
You must grant Heroku dynos access to your RDS instance. The recommended way to do this is to configure the RDS instance to only accept SSL-encrypted connections from authorized users and configure the security group for your instance to permit ingress from all IPs, eg 0.0.0.0/0.

Laravel 5.3 wont connect to mysql

I created a new user on my Macbook Air (OS X Version 10.11.2). The new user has full administrator access. I'm using MAMP. The MySQL port is set to 3306. I can connect to MySQL with everything else just fine. All of my Laravel projects stopped connecting to MySQL. When i try to use
php artisan migrate
I get:
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
Here is the database portion of my .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=store
DB_USERNAME=clerk
DB_PASSWORD=inventory
I have tried using the root user and password. I have tried using different ports. I have tried switching the host to localhost. I have verified that the username and password are correct, and that the user has access to the database.
Here is the MySQL portion of my config/database.php file:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'store'),
'username' => env('DB_USERNAME', 'clerk'),
'password' => env('DB_PASSWORD', 'inventory'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
I have been searching for a few days, and i can't seem to find the answer. My old Laravel 5.2 projects won't connect either. I'm pretty sure that this was caused by creating a new user, but i don't know enough about MySQL to figure out the problem.
Having followed troubleshooting processes as I've suggested in comments below your question, all should be working as expected.
Should that not be the case, you must be missing something; ... a PATH issue I presume.
I suggest you export your database, uninstall your MySQL, then download a new one at here.
Follow the approach elaborated here for a possible fix.
With this, your challenge will surely be addressed.
Try changing your db_host = localhost:3306
You define an engine = null. The engine is used inside the MySqlGrammar.php specifically when compiling a create query as far as I know. I have only seen null engines for VIEWS.
Try the following config:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'store'),
'username' => env('DB_USERNAME', 'clerk'),
'password' => env('DB_PASSWORD', 'inventory'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
You did mention it in your question and take it that the following works from a terminal
mysql -uclerk -pinventory -h127.0.0.1 -P3306 store
Could be that it needs to be
mysql -uclerk -pinventory -hlocalhost -P3306 store
Something else you can check with just an info.php file in your project to double check that everything seems fine with the reference to PDO as a module.
<?php
phpinfo();
Then also play around with just a little PDO php script to see if your connection is working properly. Something like:
<?php
$servername = "127.0.0.1";
$username = "clerk";
$password = "inventory";
try {
$conn = new PDO("mysql:host=$servername;port=3306;dbname=store;", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
Something else you can also check inside a dummy route what env('DB_DATABASE') etc gives you.
Updated things to check 2016.09.15
To make sure that env() is fetching the correct information include the route below and then include the output of the following:
Route::get('dbtest', function () {
$config = [
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
];
dd($config);
});
Then also access mysql as the root user and include the output of the select statement:
mysql> select host, user, password, authentication_string, password_expired from mysql.user;
As you are using MAMP make sure to use the mysql commandline tool from /Applications/MAMP/Library/bin/mysql
It's been solved. After a few hours of pulling my hair out, i decided to take #nyedidikeke advice and re-install mysql. I was using MAMP, and I have been wanting to stop using it for a while. I uninstalled it, and installed mysql through Homebrew. Everything is working just fine, thanks for all your help!

SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9) Laravel

I'm getting this error when trying to connect to an SQL Server DB from Laravel 4.2.
Here's my DB config:
'connections' => array(
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'example.noip.me',
'database' => 'db',
'username' => 'sa',
'password' => 'pass',
'prefix' => '',
),
),
//...
It works perfectly in my home computer, but not in production. This project is in a hosting service, so I can't change much of the config (can still use ini_set though).
I tried adding the port to the server address but it didn't work.
Edit: I forgot to mention that the hosting and the database server are on different computers, so it could be a security configuration problem.
I contacted tech support and it turned out to be a matter of configuration in the hosting server (Remote Database Access Hosts, which I thought was for MySQL only).

Categories