我試圖使用Google App腳本將Google表單連接到Azure上託管的SQL Server實例(DBaaS)。我不斷收到一條錯誤消息,指出我的連接字符串無效,儘管我多次嘗試修改代碼。我可以使用本地計算機上的Microsoft SQL Server Management Studio和HeidiSQL連接到Azure上的SQL Server實例。請注意,我列出了每個IP地址(0.0.0.0到255.255.255.255)以確保它不是阻止我連接的防火牆問題。將Google App腳本連接到Azure上的SQL Server(DBaaS)
//var conn = Jdbc.getConnection('jdbc:sqlserver:MyDBName.database.windows.net:1433/MyDBName', 'MyDBUserName', 'MyDBPassword');
// SECOND ITERATION OF CONNECTION STRING
//var conn = Jdbc.getConnection('jdbc:sqlserver://MyDBName.database.windows.net:1433;'+ 'databaseName=MyDBName;user=MyDBUserName;password=MyDBPassword;');
// THIRD ITERATION OF CONNECTION STRING
//var conn = Jdbc.getConnection('jdbc:sqlserver://MyDBName.database.windows.net/MyDBName:1433', 'MyDBUserName', 'MyDBPassword');
// FOURTH ITERATION OF CONNECTION STRING
//var conn = Jdbc.getConnection('MyDBName.database.windows.net','MyDBUserName', 'MyDBPassword');
// FIFTH ITERATION OF CONNECTION STRING
//var conn = Jdbc.getConnection('jdbc:sqlserver://MyDBName.database.windows.net', {user:'MyDBUserName', password:'MyDBPassword'});
// SIXTH ITERATION OF CONNECTION STRING
//var conn = Jdbc.getConnection('MyDBName.database.windows.net', {user:'MyDBUserName', password:'MyDBPassword'});
// SEVENTH ITERATION OF CONNECTION STRING
//var conn = Jdbc.getConnection('jdbc:sqlserver://MyDBName.database.windows.net:1433/MyDBName', {user:'MyDBUserName', password:'MyDBPassword'});
// EIGHT ITERATION OF CONNECTION STRING
//https://developers.google.com/apps-script/reference/jdbc/jdbc
//var conn = Jdbc.getConnection('jdbc:sqlserver://MyDBName.database.windows.net/MyDBName:1433', {user:'MyDBUserName', password:'MyDBPassword'});
// NINTH ITERATION OF CONNECTION STRING - Now I'm just throwing anything at the wall and seeing what sticks!
//var conn = Jdbc.getConnection('jdbc:sqlserver://MyDBName.database.windows.net/MyDBName;user=MyDBUserName;password=MyDBPassword');
// TENTH ITERATION OF CONNECTION STRING
//var conn = Jdbc.getConnection('jdbc:mysql://MyDBName.database.windows.net/MyDBName:1433', {user:'MyDBUserName', password:'MyDBPassword'});
// ELEVENTH ITERATION OF CONNECTION STRING
//var conn = Jdbc.getConnection('jdbc:sqlserver://MyDBName.database.windows.net:1433;databaseName=MyDBName','MyDBUserName','MyDBPassword');
//TWELVTH
//var conn = jdbc:sqlserver://MyDBName.database.windows.net;database=MyDBName;user=MyDBUserName;password=MyDBPassword;
// THIRTEENTH
//var conn = Jdbc.getConnection('jdbc:sqlserver://MyDBName.database.windows.net;user=MyDBUserName;password=MyDBPassword;databaseName=MyDBName;');
// FOURTEENTH
//var conn = Jdbc.getConnection("jdbc:sqlserver//MyDBName.database.windows.net:1433;databaseName=MyDBName;user=MyDBUserName;password=MyDBPassword");
// FIFTEENTH
//var conn = Jdbc.getConnection("jdbc:sqlserver://MyDBName.database.windows.net:1433;databaseName=MyDBName","MyDBUserName","MyDBPassword");
// SIXTEENTH
// http://stackoverflow.com/questions/18978380/error-when-connecting-to-mssql-server-with-google-apps-script-via-jdbc?rq=1
//var conn = Jdbc.getConnection("jdbc:sqlserver://NumericalIPAddress:1433;" + "databaseName=MyDBName;user=MyDBUserName;password=MyDBPassword;");
// SEVENTEENTH
// same as above with one less semicolon
//var conn = Jdbc.getConnection("jdbc:sqlserver://NumericalIPAddress:1433;" + "databaseName=MyDBName;user=MyDBUserName;password=MyDBPassword");
//EIGHTEENTH
// http://stackoverflow.com/questions/15440939/querying-sql-server-with-google-apps-script-via-jdbc
var conn = Jdbc.getConnection("jdbc:sqlserver://MyDBName.database.windows.net:1433;databaseName=MyDBName","MyDBUserName","MyDBPassword");
或者,如果您正在使用新版本的Azure門戶([https://portal.azure.com](https://portal.azure.com)),則可以找到連接字符串通過瀏覽所有> SQL數據庫> MyDBName>顯示數據庫連接字符串。 – tmullaney
真棒,我直接添加到答案! – cbattlegear
謝謝@cbattlegear –