[英]Google Cloud - Connect Sql Server to Google Apps Script
I have problems to connect sql server on google cloud to google apps script, have tried many options do url connection like: Jdbc.getCloudSqlConnection("jdbc:google:mysql://apis-para-pap:southamerica-east1:revistamarcasserver","sqlserver", "*****");我在将google cloud 上的 sql server连接到 google apps 脚本时遇到问题,尝试了很多选项来进行 url 连接,例如:Jdbc.getCloudSqlConnection("jdbc:google:mysql://apis-para-pap:southamerica-east1:revistamarcasserver", "sqlserver", "*****"); but is not connecting, Exception: Failed to establish a database connection.
但未连接,异常:无法建立数据库连接。 Check connection string.
检查连接字符串。 Do you can help me to solve this problem to connect Sql Server to Google Apps Script ?
你能帮我解决这个问题,将 Sql Server 连接到 Google Apps 脚本吗?
Information about google cloud Sql Server:谷歌云Sql Server的相关资料:
(observation: Using sql server management studio, i have tested and connected successfully, with this informations). (观察:使用 sql server management studio,我已经成功测试并连接了这些信息)。
Thank you so much太感谢了
I created a Cloud SQL instance , authorize the following IP ranges and was able to connect to it using the Public Ip Address.我创建了一个Cloud SQL 实例,授权了以下 IP 范围,并能够使用公共 IP 地址连接到它。 I could not connect using Instance connection name.
我无法使用实例连接名称进行连接。
var db = 'mydatabase';
var instanceUrl = "jdbc:mysql://Public_IP_address_SQL";
var dbUrl = instanceUrl + '/' + db;
/**
* Create a new database within a Cloud SQL instance.
*/
function createDatabase() {
var conn = Jdbc.getConnection(instanceUrl,{user: 'root', password: '****'} );
conn.createStatement().execute('CREATE DATABASE ' + db);
}
/**
* Create a new user for your database with full privileges.
*/
function createUser() {
var conn = Jdbc.getConnection(dbUrl,{user: 'root', password: '****'});
var stmt = conn.prepareStatement('CREATE USER ? IDENTIFIED BY ?');
stmt.setString(1, user);
stmt.setString(2, userPwd);
stmt.execute();
conn.createStatement().execute('GRANT ALL ON `%`.* TO ' + user);
}
/**
* Create a new table in the database.
*/
function createTable() {
var conn = Jdbc.getConnection(dbUrl, {user: 'new_user', password: '****'});
conn.createStatement().execute('CREATE TABLE entries '
+ '(guestName VARCHAR(255), content VARCHAR(255), '
+ 'entryID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(entryID));');
}
createDatabase()
createUser()
createTable()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.