2

I'm trying to connect to a Firebird database with NodeJS, and I'm using the node-firebird package link here, and am having the following error when trying to connect.

Error

node index.js
Error: Connection is closed.
    at exports.Connection.Connection._queueEvent (C:\Users\JEFTER\Documents\firebird-node-dev\node_modules\node-firebird\lib\index.js:3117:22)
    at exports.Connection.Connection.connect (C:\Users\JEFTER\Documents\firebird-node-dev\node_modules\node-firebird\lib\index.js:3152:10)
    at C:\Users\JEFTER\Documents\firebird-node-dev\node_modules\node-firebird\lib\index.js:1587:13
    at Socket.<anonymous> (C:\Users\JEFTER\Documents\firebird-node-dev\node_modules\node-firebird\lib\index.js:2828:17)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at TCP._handle.close [as _onclose] (net.js:561:12)
C:\Users\JEFTER\Documents\firebird-node-dev\index.js:19
    db.query('SELECT * FROM TEST', function(err, result) {
       ^

TypeError: Cannot read property 'query' of undefined
    at C:\Users\JEFTER\Documents\firebird-node-dev\index.js:19:8
    at doError (C:\Users\JEFTER\Documents\firebird-node-dev\node_modules\node-firebird\lib\index.js:1244:9)
    at C:\Users\JEFTER\Documents\firebird-node-dev\node_modules\node-firebird\lib\index.js:1589:17
    at exports.Connection.Connection._queueEvent (C:\Users\JEFTER\Documents\firebird-node-dev\node_modules\node-firebird\lib\index.js:3117:13)
    at exports.Connection.Connection.connect (C:\Users\JEFTER\Documents\firebird-node-dev\node_modules\node-firebird\lib\index.js:3152:10)
    at C:\Users\JEFTER\Documents\firebird-node-dev\node_modules\node-firebird\lib\index.js:1587:13
    at Socket.<anonymous> (C:\Users\JEFTER\Documents\firebird-node-dev\node_modules\node-firebird\lib\index.js:2828:17)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at TCP._handle.close [as _onclose] (net.js:561:12)

Structure

┌─data
│ └─TEST.FDB
├─node_modules
├─index.js
├─package.json
└─package-lock.json

index.js

const firebird = require('node-firebird')
const options = {
    host: '127.0.0.1',
    port: 3050,
    database: 'C:/Users/JEFTER/Documents/firebird-node-dev/data/TEST.FDB',
    user: 'SYSDBA',
    password: 'masterkey',
    lowercase_keys: false, // set to true to lowercase keys
    role: null,            // default
    pageSize: 4096         // default when creating database
}

firebird.attach(options, (err, db) => {

    if (err)
        console.log(err)

    // db = DATABASE
    db.query('SELECT * FROM TEST', (err, result) => {
        // IMPORTANT: close the connection
        db.detach()
    })
})

My Firebase: version 2.5.x, OS: Windows 10

The TEST.fbd database has a table TEST with 2 users with id and name.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Jefter Rocha
  • 387
  • 2
  • 14
  • Are you sure Firebird is running, and is listening on 127.0.0.1 port 3050? – Mark Rotteveel Dec 05 '18 at 10:07
  • @MarkRotteveel yeah, it's running in my local machine. – Jefter Rocha Dec 05 '18 at 10:22
  • About `index.js`, this code is the same in the sample on the package page, so I guess nothing wrong should happen. – Jefter Rocha Dec 05 '18 at 10:25
  • 1
    Try windows path, `database: 'C:\\Users\\JEFTER\\Docu... etc` ? – Arioch 'The Dec 05 '18 at 10:57
  • Even if Firebird is running, some antivirus or firewall may prohibit node-JS runtime to connect to it. You may stop your program before `db.query` and connect the database with some Firebird IDE ( IBExpert, flameRobin, etc ) with `SYSDBA` username, then check `MON$ATTACHMENTS` table - if there is node-JS's connections or only your IDE's one. – Arioch 'The Dec 05 '18 at 11:01
  • I have tried the exact same code (only difference being the database path) and it works fine for me. Not having Firebird started (or a different port), or a wrong username/password, or non-existent database all produce different errors, so I'm not sure what is wrong. I did use node.js 8; I'll see what happens if I upgrade to node.js 10. – Mark Rotteveel Dec 05 '18 at 15:37
  • 1
    Node 10 also works fine for me, the only thing I can think of is maybe a firewall rule interfering (blocking the connection or killing the connection). – Mark Rotteveel Dec 05 '18 at 15:50

0 Answers0