Node/Tedious not triggering "done" event
<p>I've started learning Node and am using Tedious to connect to and query a DB.</p>

<p>I've written a module, <code>db</code>, which exports the following functions:</p>

<pre><code>exports.connect = function(callback) {
    console.log("\n** 1. open db");
    db = new Connection(local.config.db_config);
    db.on("connect", callback);
};

exports.disconnect = function(callback) {
    console.log("db.disconnect");
    if (!db) {
        return;
    }

    db.on("close", callback);
};

exports.query = function(cbQuery, cbRow, cbDone) {
    var Request = require("tedious").Request,
        request = new Request("SELECT * FROM Clients", cbQuery);

    if (typeof(cbRow) === "function") {
        request.on("row", cbRow);
    }

    if (typeof(cbDone) === "function") {
        request.on("done", cbDone);
    }

    db.execSql(request);
};
</code></pre>

<p>I then have the standard <code>server.js</code> in which I call those exported functions using the following:</p>

<pre><code>var dbConnected = function(err) {
        if (err) {
            console.error("** FATAL ERROR ON CONNECT: ");
            console.error(err);
            process.exit(-1);
        }
        console.log("DB connected");

        db.query(dbQueryCallback, dbOnRows, dbOnDone);
    },
    dbDisconnected = function (err) {
        console.log("dbDisconnected");
        if (err) {
            console.error("** FATAL ERROR ON DISCONNECT: ");
            console.error(err);
            process.exit(-1);
        }

        console.log("DB disconnected");
    },
    dbQueryCallback = function (err, rowCount, rows) {
        if (err) {
            console.error("ERROR DURING QUERY:");
            console.error(err);
            process.exit(-1);
        }
        console.log("Query rowCount = " + rowCount);
    },
    dbOnRows = function(columns) {
        columns.forEach(function(column) {
            if (column.value === null) {
                console.log("NULL");
            } else {
                console.log(column.metadata.colName + ": " + column.value);
            }
        });
    },
    dbOnDone = function(rowCount, more, rows) {
        console.log("done");

        db.disconnect(dbDisconnected);
    };

db.connect(dbConnected);
</code></pre>

<p>When run, the DB connection is successfully opened, a simple query is executed and its results are written to the console (by the <code>dbOnRows</code> handler).</p>

<p>However, the <code>dbOnDone</code> handler is never triggered, so the connection is never closed.</p>

<p>Can anyone explain why <code>dbOnDone</code> is not being triggered?</p>