title: Querying SQL Server with Google Apps Script via JDBC
body: <p>I'm using SQL Server 2008 R2 and am trying to query it using Google Apps Script. I'm using one of the suggested scripts that's supposed to populate a spreadsheet but i'm having problems connect with SQL.</p>
  
  <p>I've checked the port i've specified is correct so I doubt the issue is that, i'd really appreciate confirmation that my connection string is right.</p>
  
  <p>Here's the code - </p>
  
  <p>server/instance:1433;databaseName=xxxx;user=xxxx;password=xxxx");</p>
  
  <pre><code>function foo() {
    var conn = Jdbc.getConnection   ("jdbc:sqlserver/instance:1433;databaseName=xxxx;user=xxxx;password=xxxx");
    var stmt = conn.createStatement();
    stmt.setMaxRows(100);
    var start = new Date();
    var rs = stmt.executeQuery("select top 1000 from SOP10100");
  
    var doc = SpreadsheetApp.getActiveSpreadsheet();
    var cell = doc.getRange('a1');
    var row = 0;
    while(rs.next()) {
      cell.offset(row, 0).setValue(rs.getString(1));
      cell.offset(row, 1).setValue(rs.getString(2));
      cell.offset(row, 2).setValue(rs.getString(3));
      cell.offset(row, 3).setValue(rs.getString(4));
      row++;
    }
    rs.close();
    stmt.close();
    conn.close();
    var end = new Date();
    Logger.log("time took: " + (end.getTime() - start.getTime()));
  </code></pre>
  
  <p>Thanks for your help!</p>