Can we connect google sheet App-Script to Google Cloud SQL (MySQL) just only private ip enable?

112 views
Skip to first unread message

LongNH4

unread,
Dec 26, 2023, 2:10:14 AM12/26/23
to Google Apps Script Community
I have a trouble about connect Google App script to Google Cloud SQL,
It  worked fine when I enable public IP for cloud SQL instance, but when I disable public IP and just only enable private IP, It cant connect and show error "Failed with an error Failed to establish a database connection. Check connection string, username and password."

Please help me :(

Anthony Vaz

unread,
Apr 3, 2024, 5:10:44 AM4/3/24
to Google Apps Script Community

I also tried to connect to Google Cloud SQL from my Google App Script.
Searched many places. The exception is showed below.
Please help me.
The error is too generic. 

The connection name and database name were taken from the Google cloud console
Connection name - copied from the overview page
database name - copied from the Database menu item under the name column

function connectToGoogleCloudSQL() {
      const connectionName = 'projectname:regionname:dbinstancename'
      const dbName = 'dbname'
      const username = 'myusername'
      const password = 'mypassword'
      const conn = Jdbc.getCloudSqlConnection("jdbc:google:mysql://${connectionName}/${dbName}", username, password);   <---- Line 130

9:04:01 AM Error
Exception: Failed to establish a database connection. Check connection string, username and password.
connectToGoogleCloudSQL @ Code.gs:130
Reply all
Reply to author
Forward
0 new messages