Error connecting Firebird database to Nodejs

Asked

Viewed 2,383 times

1

I’m trying to connect to a Firebird test bench with Nodejs, and I’m using the package node-firebird, and I’m having the following mistake:

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()
    })
})

The version of Firebase is the 2.5x, I’m using Windows 10.

The bank TEST.fbd has a table TEST with 2 users with id and nome.

  • Can you tell us how you connect to this same bank in your bank management tool or something to check the information?

  • Was any of the answer helpful? Don’t forget to choose one and mark it so it can be used if someone has a similar question!

  • Good morning! I had this same problem when connecting Firebird 3.0 to a Node.js application on two linux machines (debian and Ubuntu), what worked for me was to change the settings in the Firebird.conf file.

1 answer

0

Try without all this configuration information to see if it is not an information conflict problem:

const firebird = require('node-firebird');
const configuracoes = {
  database: 'C:/Users/JEFTER/Documents/firebird-node-dev/data/TEST.FDB',
  user: 'SYSDBA',
  password: 'masterkey',
};

const pool = firebird.pool(5, configuracoes);

const executar = (query) => {
  return new Promise((resolver, rejeitar) => {
    pool.get((err, db) => {
      if (err) {
        rejeitar(err);
        return;
      }

      db.query(query, (erro, resultado) => {
        if (erro) {
          rejeitar(err);
          return;
        }

        db.detach();
        resolver(resultado);
      });
    });
  });
}

(async () => {
  console.log(await executar('SELECT * FROM TEST'));
})();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.