googleworkspace / apps-script-samples

Apps Script samples for Google Workspace products.
https://developers.google.com/apps-script
Apache License 2.0
4.5k stars 1.83k forks source link

Remote SQL is not accessible by Google #353

Closed Khnaz35 closed 1 year ago

Khnaz35 commented 2 years ago

Summary

No matter what Google doesn't connect with My SQL TODO Connect my sql databse with google sheet.

I am trying my code as below but not able to connect no matter what!

`var server = "162.111.11.111";

var dbName = "abcdef_3.0.2.0";

var username = "gqvxzdmy_google";

var password = "b.$teCEhHCenXA029";

var url = 'jdbc:mysql://'+server+'/'+dbName;

function readData() {

var conn = Jdbc.getConnection(url, username, password);

var stmt = conn.createStatement();

var results = stmt.executeQuery('SELECT * FROM oc_order');

var metaData=results.getMetaData();

var numCols = metaData.getColumnCount();

var spreadsheet = SpreadsheetApp.getActive();

var sheet = spreadsheet.getSheetByName('Sheet1');

sheet.clearContents();

var arr=[];

for (var col = 0; col < numCols; col++) {

arr.push(metaData.getColumnName(col + 1));

}

sheet.appendRow(arr);

while (results.next()) {

arr=[];

for (var col = 0; col < numCols; col++) {

arr.push(results.getString(col + 1));

}

sheet.appendRow(arr);

}

results.close();

stmt.close();

sheet.autoResizeColumns(1, numCols+1);

}`

Upon running the code i am facing error: Exception: Failed to establish a database connection. Check connection string, username and password. (line 19, file "Code")

I have double check the username password all are fine (tried SQL Pro to connect on my localhost and its works fine) I have whitelisted the Ip range also on my server from this url: https://www.gstatic.com/ipranges/goog.txt