title: Calling Azure SQL from Azure Functions node.js
body: <p>I'm trying to use tedious library to inject simple insert from the incoming body. No error is thrown, but context.logs placed inside the functions are not displaying in logs. As a result in DB I have row with NULL values instead of what is passed. Any idea what am I doing wrong?
  Is there any other library/method of accessing the Azure DB from Azure Functions or I am stuck with Tedious?
  Of course I could probably use Azure Logic App but its  more expensive to run than Azure Functions.</p>
  
  <pre><code>var Connection = require('tedious').Connection;
  var Request = require('tedious').Request;
  var TYPES = require('tedious').TYPES;
  var globalheaders = {
      Id: '1233',
      Name: 'Ant',
      Payment: "2019-10-09",
      Type: 'Fixed cost',
      Value: 156,
      Cycle: '1',
      Frequency: 'month'
  }
  
  module.exports = async function (context, req) {
      context.log('JavaScript HTTP trigger function processed a request.');
      globalheaders = req.body;
      context.log(globalheaders);
  var config = {  
          server: '********.database.windows.net',  //update me
          authentication: {
              type: 'default',
              options: {
                  userName: '*******', //update me
                  password: '*******'  //update me
              }
          },
          options: {
              // If you are on Microsoft Azure, you need encryption:
              encrypt: true,
              database: 'cashmandb'  //update me
          }
      }; 
      var connection = new Connection(config);
      await connection.on('connect', function(err) {
  
          if (err) {
              context.log(err);
  
              context.res = {
                  status: 500,
                  body: "Unable to establish a connection."
              };
              context.done();
  
  
          } else {
              context.log('before execution');
              executeStatement();
          }
      });
  context.log('connection executed')
      async function executeStatement() {  
          request = new Request("INSERT dbo.cost (Id, Name, Payment, Type, Value, Cycle, Frequency) OUTPUT INSERTED.Id VALUES (@Id, @Name, @Payment, @Type, @Value, @Cycle, @Frequency);", function(err) {  
           if (err) {  
              context.log(err);}  
          });  
          context.log('executestatement')
          request.addParameter('Id', TYPES.NChar,globalheaders.id);  
          request.addParameter('Name', TYPES.NVarChar , globalheaders.name);  
          request.addParameter('Payment', TYPES.Date, globalheaders.payment);  
          request.addParameter('Type', TYPES.NVarChar,globalheaders.type); 
          request.addParameter('Value', TYPES.Int,globalheaders.value);  
          request.addParameter('Cycle', TYPES.NChar,globalheaders.cycle); 
          request.addParameter('Frequency', TYPES.NChar,globalheaders.frequency); 
          request.on('row', function(columns) {  
              columns.forEach(function(column) {  
                if (column.value === null) {  
                  context.log('NULL');  
                } else {  
                  context.log("Product id of inserted item is " + column.value);  
                }  
              });  
          });       
  
          await connection.execSql(request);
      }
  
      context.done();
  };
  </code></pre>