节点JS setInterval。 TypeError:无法读取属性' apply'未定义的

时间:2015-07-24 08:27:12

标签: .net node.js timer error-handling

我是Nowfal,一名c#程序员。我是Node JS的新手。 当我创建一个函数并给出setInterval内部时出现错误 TypeError:无法读取属性' apply'未定义的

at wrapper [as _onTimeout](timers.js:274:13)

在Timer.listOnTimeout(timers.js:119:15)

我的代码页在下面给出

第1页(Server.js)

var db = require('./dbConnect.js');
var ins = require('./dbInsert.js');

var tagId = [];
var schoolInfoId = [];
var imeNo = [];
var totalRows = 0;

function ViewQuery() {
    var mysql = db.mysql;
    var connection = db.createMyConnection();


    connection.connect();


    var mycommand = "SELECT     t.skha_tag_id_no,s.skha_school_info_id,a.skha_out_device_imeno" +
        " FROM skha_tag t INNER JOIN skha_student_info s on skha_tag_id     = skha_student_tag_id_no " +
         " INNER JOIN skha_student_school_attendance a on     a.skha_student_info_id = s.skha_student_info_id" +
         " WHERE DATE(skha_student_in_time) = CURDATE() AND     skha_student_out_time IS NULL and skha_out_status = 1 ";

     connection.query(mycommand, function (err, rows) {
        if (!err) {

         var result;
            for (i = 0; i < rows.length; i++) {
                totalRows++;

                result = rows[i];

                tagId.push(result['skha_tag_id_no']);
                schoolInfoId.push(result['skha_school_info_id']);
                imeNo.push(result['skha_out_device_imeno']);

            }


            for (i = 0; i < totalRows; i++) {
                ins.insertDB(tagId[i], schoolInfoId[i], imeNo[i]);
            }

        }
        else
            console.log('Error while performing Query.');
    });

    connection.end();

};

setInterval(ViewQuery(),30000); //Error Generating from here

第2页(dbConnect.js)

var mysql = require('mysql');

exports.createMyConnection = function createMyConnection() {
    var connection = mysql.createConnection( {
        host    : '192.168.0.175',
        user    : 'ss_user',
        password : 'df33-ccff2188',
        database : 'shkaliasdb',
        multipleStatements: true
    });
    return connection;
}

exports.mysql = mysql;

第3页(dbInsert.js)

var db = require('./dbConnect.js');

var logOutTimeInterval = 5;
exports.insertDB = function (RFID, schoolID, imei) {

    var mysql = db.mysql;
    var connection = db.createMyConnection();

    connection.connect();
    console.log('IMEI : ' + imei);
    console.log(RFID);



    str = "SET @OutStatus=0;SET @logOutTime=0;call     out_mark_save_two_device('" + RFID + "'," + schoolID + "," +      logOutTimeInterval + ",@OutStatus,@logOutTime," + imei + ")";

    console.log(str);


    connection.query(str, function (err, rows, fields) {//, fields
        if (err)
            console.log('Error while performing Query.' + err);
         else {
            console.log(rows[0]);

        }
    });

    connection.end();


};

首次代码正常运行,然后显示错误消息,计时器无法正常工作。

请给我任何解决方案...... 在此先感谢..

1 个答案:

答案 0 :(得分:-2)

显示来自timers.js的代码。 你打电话给#34;申请&#34;未定义对象的方法。方法&#34;申请&#34;工作