Set the connection timeout when using Node.js

Demonstrates configuring the connection timeout when connecting to Cloud SQL for SQL Server using the Node.js mssql module.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

Node.js

To authenticate to Cloud SQL for SQL Server, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

// 'connectionTimeout` is the maximum number of milliseconds to wait trying to establish an
// initial connection. After the specified amount of time, an exception will be thrown.
config.connectionTimeout = 30000;
// 'acquireTimeoutMillis' is the number of milliseconds before a timeout occurs when acquiring a
// connection from the pool.
config.pool.acquireTimeoutMillis = 30000;
// 'idleTimeoutMillis' is the number of milliseconds a connection must sit idle in the pool
// and not be checked out before it is automatically closed
(config.pool.idleTimeoutMillis = 600000),

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.