3

I am using node-mssql module for connecting to SQL server. It all works nicely. I have a problem that happens quite randomly and not sure why. So, I did a bit of testing. I create a connection pool with

var connection = new sql.Connection({ /* config */ });

and the fired a query in it, after some timeout which works well. Now to test how it handles interruption, After creating connection (in above code), I stop the SQL server, also tried disconnecting network connection. I had hoped that I would get some error in the query, but it goes on infinite. Nothing is getting caught in error handler as well, defined like

connection.on('error', function(err) {
    console.error("Error detected in connection creation");
    console.error(err);
});

I have used PreparedStatement though. Something like below

const ps = new sql.PreparedStatement(connection)
ps.input('param', sql.Int)
ps.prepare('select @param as value', err => {
    // ... error checks

    ps.execute({param: 12345}, (err, result) => {
        // ... error checks

        console.log(result.recordset[0].value) // return 12345
        console.log(result.rowsAffected) // Returns number of affected rows in case of INSERT, UPDATE or DELETE statement.

        ps.unprepare(err => {
            // ... error checks
        })
    })
})

So, the ps.execute never returns callback, not even after requestTimeout time. Thanks in advance for any help/guidance.

Update I tried debug option in node-mssql and here is the last output I got while it's stuck.

    Sent
  type:0x03(RPC_REQUEST), status:0x01(EOM), length:0x00B3, spid:0x0000, packetId:0x01, window:0x00
  0000  16000000 12000000 02000000 00000000 00000100 00000A00 73007000 5F007000  ........ ........ ........ s.p._.p.
  0020  72006500 70006100 72006500 00000740 00680061 006E0064 006C0065 00012604  r.e.p.a. r.e....@.h.a.n.d.l.e..&.
  0040  00074000 70006100 72006100 6D007300 00E70200 00000000 00000005 40007300  ..@.p.a. r.a.m.s. ........ ....@.s.
  0060  74006D00 740000E7 3A000000 0000003A 00730065 006C0065 00630074 00200074  t.m.t... :......:.s.e.l.e.c.t. .t
  0080  006F0070 00200031 0020002A 00200066 0072006F 006D0020 00730070 0068005F  .o.p. .1. .*. .f.r.o.m. .s.p.h._
  00A0  00750073 00650072 007300  .u.s.e.r.s.
  RPC Request - sp_prepare
State change: LoggedIn -> SentClientRequest

Sent
  type:0x06(ATTENTION), status:0x01(EOM), length:0x0008, spid:0x0000, packetId:0x01, window:0x00

State change: SentClientRequest -> SentAttention
Gautam Kumar Samal
  • 758
  • 1
  • 7
  • 23

0 Answers0