locked
azure custom apis: performing database transaction returns a timeout RRS feed

  • Question

  • On a azure custom api, I'm attempting to perform bulk insert operation to three tables utilising database transactions.Then I'm facing this error on the console.

    The request 'POST /api/saveinvite' has timed out. This could be caused by a script that fails to write to the response, or otherwise fails to return from an asynchronous call in a timely manner.

    exports.post = function(request, response) {
    var jsonfriendcircle=request.body.jsonfriendcircle;
    var jsoninviteelist=request.body.jsoninviteelist;
    var jsoninviteefriendcirclelist=request.body.jsoninviteefriendcirclelist;
    var mssql=request.service.mssql; 
    
    mssql.open({ success:function(connection){
        connection.beginTransaction(function(error)
        {
          var sqlst1='insert into FriendCircle (id,circle_name)values(?,?)' ;
           connection.query(sqlst1,[jsonfriendcircle.id,jsonfriendcircle.circle_name],function(err,results){
               if((err!=null)){
                   console.log("Error :" +err);
                   connection.rollback();
                   response.send(statusCodes.Error,{message:'error in executing inserting into friendcircle'});
                   connection.close();
                   return;
               }
           });
           for(var property in jsoninviteelist){
           var sqlst2='insert into Invitee(invitee_id,invited_by) values(?,?)';
           connection.query(sqlst2,[jsoninviteelist.property.invitee_id,jsoninviteelist.property.invited_by],function(err,results){
               if((err!=null)){
                   console.log("Error :" +err);
                   connection.rollback();
                   response.send(statusCodes.Error,{message:'error in executing inserting intoinviteelist'});
                   connection.close();
                   return;
               }
    
           });
           }
           for(var property in jsoninviteefriendcirclelist){
               var sqlst3='insert into Invitee_FriendCircle(invitee_id,friendcircleid,request_accept_status) values(?,?,?)';
               connection.query(sqlst3,[jsoninviteefriendcirclelist.property.invitee_id,jsoninviteefriendcirclelist.property.friendcircleid,jsoninviteefriendcirclelist.property.request_accept_status],function(err,results){
                   if((err!=null)){
                   console.log("Error :" +err);
                   connection.rollback();
                   response.send(statusCodes.Error,{message:'error in executing inserting into inviteefriendcircle'});
                   connection.close();
                   return;
               }else{
                   connection.commit();
                   response.send(statusCodes.OK,{message:'Transaction successful!'});
                   connection.close();
               }
    
               });
           }
    
        });
    
    
    },error:function(err){
        console.log("Error :" +err);
        response.send(statusCodes.Error,{message:err});
    }
    
    });   
    
    };


    • Edited by LakshithaR Monday, February 1, 2016 2:45 PM
    Monday, February 1, 2016 2:44 PM