I have a laravel application that connect a sql server db on Azure.
On my local Wamp server the application works. I have installed on my linux server using a docker image, and don't connect the Azure DB. Every time returns this error message:
SQLSTATE[HYT00]: [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (SQL: select * from [mytable])
MSDOBC Driver, sqlsrv and pdo_sqlsrv are correctly installed.
I suppose is something related with laravel because if I query the db with a php script works without problem.
My .ENV file has db settings:
DB_CONNECTION=sqlsrv
DB_HOST=db.database.windows.net
DB_PORT=1433
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD=pwd
Laravel log and docker log don't tell nothing interesting, I don't have any idea how to solve.
Azure SQL Database supports only the tabular data stream (TDS) protocol (accessible over TCP and the default port of 1433) and uses its own IP-based firewall. So you may try the following:
Use connection string with protocol, server name and port. In your case you need to use tcp:db.database.windows.net,1433
as a value of DB_HOST
.
Add the IP address of your LINUX server as a firewall rule. This is explained in the documentation:
When a computer tries to connect to your server from the internet, the firewall first checks the originating IP address of the request against the database-level IP firewall rules for the database that the connection requests.
If the address is within a range that's specified in the database-level IP firewall rules, the connection is granted to the database that contains the rule.
If the address isn't within a range in the database-level IP firewall rules, the firewall checks the server-level IP firewall rules.
If the address is within a range that's in the server-level IP firewall rules, the connection is granted. Server-level IP firewall rules apply to all databases managed by the server.
If the address isn't within a range that's in any of the database-level or server-level IP firewall rules, the connection request fails