'connection to database timing out in less than 30 seconds despite 300 second timeout in conn string

I am opening a connection to a sql azure serverless database. This database pauses if unused for 1 hour.

I connect to this database via an azure function. The conn.open(); line times out after 10 seconds despite the connection string having timeout set to 300 seconds. The database is also not unpausing on this connection attempt.

I had assumed that when a connection is made it will restart, and this may take a few minutes but the code seems to be ignoring the connection string timeout value.

Is there somewhere else i should set this timeout?

Conn String:

Server=tcp:myDBServer.database.windows.net,1433;Initial Catalog=sample-Db;Persist Security Info=False;User ID={your_user};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=300;


Solution 1:[1]

More than 30 minutes idle connections can be closed by Azure SQL Database.

If you're connected from SSMS or any other applications to the Azure SQL DB for longer than 30 minutes without any active request, your session will timeout.

The default idleTimeout parameter before closing an unused connection is 300000 ms which would be enough for Azure SQL Connections.

Please check the workarounds given in this thread:

How can I avoid a SqlClient timeout error during execution of a C# Azure Function?

Solution 2:[2]

The Connection Timeout in the ConnectionString only controls the timeout for the connection. If you need to increase the wait time on your Commands, use the CommandTimeout property of SqlCommand.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DelliganeshS-MT
Solution 2 shehan pathirathna