使用DDNS和端口转发的Google Apps脚本JDBC(专门针对sqlserver)连接问题

时间:2019-03-24 12:15:21

标签: sql-server jdbc google-apps-script

我有一个Google Apps脚本,我正在尝试使用JDBC连接到在本地计算机上运行的sqlserver。我无法连接脚本,“无法建立连接,请检查severUrl,用户名密码”  我已将Google JDBC服务文档中指定的IP范围列入白名单。我还在路由器上配置了DDNS和端口转发。我可以使用DDNS名称成功连接到SSMS。我还使用似乎成功的测试工具执行了JDBC连接测试。请参阅下面的屏幕截图。我曾尝试在脚本中调整连接网址,但不走运! :/有人可以关注我的代码并提供帮助吗?预先感谢。

var url = 'jdbc:sqlserver://'+host+':'+port+'/'+databaseName;

  //var testUrl = 'jdbc:sqlserver://661607384698.sn.mynetname.net;databaseName=COSMOS_FinalBuild;user=sa1;password=*****';


  var sql = 'SELECT * FROM ' + tableName;

  try{    
    //var connection = Jdbc.getConnection(url, userName, password);
    //var connection = Jdbc.getConnection(testUrl);
    var connection = Jdbc.getConnection("jdbc:sqlserver://661607384698.sn.mynetname.net:1433;databaseName=COSMOS_FinalBuild;user=sa1;password=****;");

JDBC测试:

jdbc test screenshot

whitelisted ips

error

@Gord:我尝试再次使用3参数getConnection方法。我的网址输出如下所示,如google脚本调试器中所示。 url output

var url = 'jdbc:sqlserver://'+host+':'+port+'/'+databaseName;
var sql = 'SELECT * FROM ' + tableName;

try{    
  var connection = Jdbc.getConnection(url, userName, password);

Google Cloud Platform日志-stacktrace:

{
 insertId:  "-bmwmk9e8vn1l"  
 jsonPayload: {
  context: {
   reportLocation: {
    filePath:  "Code"     
    functionName:  "readFromTable"     
    lineNumber:  26     
   }
  }
  message:  "Failed to establish a database connection. Check connection string, username and password.
    at readFromTable(Code:26)
"   
  serviceContext: {
   service:  "AKfycby9I5yUlkZy8L7IVmNX1JQOAIzO1TKiRR7Lus1BGlI"    
  }
 }
 labels: {
  script.googleapis.com/deployment_id:  "AKfycby9I5yUlkZy8L7IVmNX1JQOAIzO1TKiRR7Lus1BGlI"   
  script.googleapis.com/process_id:  "EAEA1GOziwooUcZfjMqR5zBR-ifoaVNHiz_vL3TZ7yRYfpZvaLDQSTGTPxXhK-aFZHq3aef6Tyc0SRjiDXJmQXVnVbC6hruqXSgOMcRo8QBFsnS0mFtEZBC0y5G_2ZavxEhfg3DJIjvRiBY8jxjlG3RKn0COwEt1Z2S5B-g"   
  script.googleapis.com/project_key:  "MtpHc9N6JeBDF-Yd2tcIAAtFKZI4u1nwX"   
  script.googleapis.com/user_key:  "AAeHopULdD4cfG3US9agmuo+hAm1kYS4RHmnnPR/3kWg5nPeH//brLoUd5kuZbFfezvczZf/RMfm"   
 }
 logName:  "projects/project-id-0363537718702516946/logs/script.googleapis.com%2Fconsole_logs"  
 receiveTimestamp:  "2019-03-24T15:49:31.080162988Z"  
 resource: {
  labels: {
   function_name:  "readFromTable"    
   invocation_type:  "editor"    
   project_id:  "project-id-0363537718702516946"    
  }
  type:  "app_script_function"   
 }
 severity:  "ERROR"  
 timestamp:  "2019-03-24T15:49:30.966Z"  
}

0 个答案:

没有答案