Azure Mobile Service : sql query result call twice (API)

Hello,

I've got a problem with the result of mssql.query in Azure mobile services.

When I send an sql query, the result function is called twice...

I don't understand because my sql query is an "update" and the result is empty (I do not have multiple lines of results)

For example, I have a function that send an email with a new password. The email is sent twice... I found a temp solution with an index but it's not very clean.

Can you explain this ?

Here is the code :

exports.put = function(request, response) {
var mssql = request.service.mssql;
    
//construct SQL query
var email = "test@toto.com";
var password = require("crypto").randomBytes(4).toString('hex');
var password_md5 = require("crypto").createHash("md5").update(password).digest("hex");
var sql = "update dbo.mytable SET password='"+password_md5+"' where id=12";

var id = 0;     //temp solution

mssql.query(sql, 
{
    success: function(results) {
        //Send email with new pwd
        if(id == 0) {
            response.send(statusCodes.OK,password_md5);
            sendEmail(email,password);
        }
        id++;   //temp solution
    },
    error: function(err) {
        response.send(statusCodes.INTERNAL_SERVER_ERROR,"Error : " + err);
    }
}); 

}

Thank you :-)

Steve

February 11th, 2015 4:29pm

I get the answer on another forum : I have to prefix my SQL statement with  set nocount on; command.

Steve

 
Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 1:14pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics