Martial's avatar

SQLSRV : Login timeout expired

I'm trying to connect to a sql server database from Laravel 10 deployed on ubuntu 22.04. but I keep getting the following error: SQLSTATE[HYT00]: [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired I installed the drivers to establish a connection to an sql server, following the Microsoft documentation. I also activated the php extensions sqlsrv and pdo_sqlsrv. I set the login timeout to 5 minutes. Despite all this, I still get the error. However, I manage to connect to the database from the command line with sqlcmd and with a php file where I use pdo for the connection. If anyone has a clue how to unblock this issue with Laravel, thank you in advance.

Ubuntu : 22.04 LTS PHP version : 8.2 Laravel : 10 packages installed : msodbcsql18 mssql-tools18 unixodbc-dev

0 likes
16 replies
Snapey's avatar

login timeout should be a couple of seconds at most. By making it 5 minutes you are forcing it to wait longer before giving up. There is something wrong with your credentials

What have you configured in your application?

1 like
Martial's avatar

My credentials works because I can connect to the database with Dbeaver and the same credentials. I configured the .env with sqlsrv driver. I put the IP and the instance of the database as DB_HOST. And I put the the credentials as DB_USERNAME and DB_PASSWORD

Snapey's avatar

have you run php artisan config:clear ?

1 like
Martial's avatar

@Snapey yes I run this command and I have the same result Is it possible that it's a problem with the host ? I put 0.0.0.0\InstanceName in my config

Snapey's avatar

@Martial cant think when that would be the right value? If it's running locally the it would be 127.0.0.1

Did you not have to specify this with Dbeaver?

Martial's avatar

@Snapey The database is stored in remote on the ip that I have in my .env file. I set the same host and credentials on dbeaver and i works well. Also with sqlcmd on the VM that is deployed the laravel app. There is no filter on ip in the sql server host. So I don't see where could be the error

Martial's avatar

solved by using the quotes on the connection info and leaving the port blank

1 like
rszabo@crowleyauto.net's avatar

@Martial I have the exact same issue, with the exact same configuration as you. I'm have been running this on an older version 18 ubuntu, msodbc 17 and it works fine. The newer setup times out. What exactly did you do to make it work? Thanks

Snapey's avatar

@[email protected] he wrote what he did.

Problem was probably a # in the password, which when unquoted, causes dotenv to consider everything after the # to be a comment.

Open tinker and run config('database') and check all values are as expected.

rszabo@crowleyauto.net's avatar

@Snapey So when I run that on my local environment it runs fine, when I run it on my server it stops 1.2 way through and leaves me at a less prompt : I have to enter q to exit. I have made sure the config file and env file are the same, but I can't get it to work. Also it shows only the defaults in what it does show. Doesn't look like it's reading the env. Thanks

rszabo@crowleyauto.net's avatar

Thanks, must be a server or driver issue. I discovered it works fine from my local environment, but not on the ubuntu server. I can ping it so I know it can get to it. Maybe I missed some configuration on the odbc driver that I didn't remember doing on the old server.

Please or to participate in this conversation.