設定使用 ADO.NET 時的連線持續時間

使用 ADO.NET 連線物件,設定連線連線至 MySQL 適用的 Cloud SQL 時,可保留的連線秒數上限。

深入探索

如需包含此程式碼範例的詳細說明文件,請參閱以下文件:

程式碼範例

C#

如要驗證 MySQL 適用的 Cloud SQL,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。

// ConnectionLifeTime sets the lifetime of a pooled connection
// (in seconds) that a connection lives before it is destroyed
// and recreated. Connections that are returned to the pool are
// destroyed if it's been more than the number of seconds
// specified by ConnectionLifeTime since the connection was
// created. The default value is zero (0) which means the
// connection always returns to pool.
connectionString.ConnectionLifeTime = 1800; // 30 minutes

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱 Google Cloud 範例瀏覽器