Connecting apps script to microsoft sql server running in cloud sql

244 views
Skip to first unread message

Hannes Härm

unread,
Jun 12, 2023, 5:38:35 AM6/12/23
to Google Apps Script Community
Hi!

I'm having trouble connecting my apps script to an sql server instance.

This is the code that should connect to the server:
function getDatabaseConnection() {
const connectionParams = {
user: database.connection.userName,
password: database.connection.password,
databaseName: database.connection.database
}

return Jdbc.getConnection(`jdbc:sqlserver://${database.connection.ip}`, connectionParams);
}

The server has a public ip, which I am giving to the connectionstring as shown above.
SSL is not required currently. I just want to get the connection running.

I have whitelisted the IP addresses listed here: https://www.gstatic.com/ipranges/goog_ipv4_only.txt

As far as I have understood connecting with getCloudSqlConnection method does not work with ms sql server.

The error I'm getting: Failed to establish a database connection. Check connection string, username and password.

What am I missing?
Thanks

cwl...@gmail.com

unread,
Jun 12, 2023, 8:43:37 AM6/12/23
to Google Apps Script Community
I don't know if this Ashton Fei example will help you specifically (ms sql) since this is for a mysql db, but may give you some ideas. 
https://youtu.be/LCt7mRT0pBE

His sheet and script can be copied from here:
https://docs.google.com/spreadsheets/d/1Ph8tKTfYWkbXyFlO4bbqCa55LPv6Ex7V3yBMCzMppV8/copy
Message has been deleted

Hannes Härm

unread,
Jun 12, 2023, 11:12:27 AM6/12/23
to Google Apps Script Community
Well the difference here is that his database is not hosted in google cloud unlike mine.

cwl...@gmail.com

unread,
Jun 12, 2023, 12:31:45 PM6/12/23
to Google Apps Script Community
Can you share your current configuration how you connect to the DB? (credentials masked of course). Or is this entirely new?

Hannes Härm

unread,
Jun 12, 2023, 4:28:23 PM6/12/23
to Google Apps Script Community
What do you mean with "configuration how you connect to the db"?

The connection is made with the function getDatabaseConnection shown above in the initial post.

The values for database.connection.userName and others are set in another script.
Reply all
Reply to author
Forward
0 new messages