我正在尝试使用App Script从本地数据库(SQL Server)连接到Google Sheet。但它表示连接错误。这是我的代码。
function SQLdb() {
// Replace the variables in this block with real values.
// Read up to 1000 rows of data from the table and log them.
function readFromTable() {
var user = 'sa';
var userPwd = 'DBpass';
var database = 'MyDBName'
var connectionString = 'jdbc:sqlserver://127.0.0.1:1433;databaseName='+database;
var conn = Jdbc.getConnection(connectionString, user, userPwd);
var start = new Date();
var stmt = conn.createStatement();
stmt.setMaxRows(1000);
var results = stmt.executeQuery('SELECT TOP 1000 * FROM dbo.myTable');
var numCols = results.getMetaData().getColumnCount();
while (results.next()) {
var rowString = '';
for (var col = 0; col < numCols; col++) {
rowString += results.getString(col + 1) + '\t';
}
Logger.log(rowString)
}
results.close();
stmt.close();
var end = new Date();
Logger.log('Time elapsed: %sms', end - start);
}
readFromTable();
}