Connection Error to Firebird DB - node.js

I have attached my code and error message on the below. Can you please help me, I could not find the reason to get the error.
Thanks,
// My Code
// Node-Firebird
var Firebird = require('node-firebird');
// Options
var options = {};
//options.host = '127.0.0.1';
//options.port = 3050;
options.database = 'mydb.FDB';
options.user = 'SYSDBA';
options.password = 'masterkey';
// Query
Firebird.attach(options, function(err, db) {
if (err)
throw err;
// db = DATABASE
db.query('SOME QUERY', function(err, result) {
// IMPORTANT: close the connection
db.detach();
});
});
// Error Message
/Users/bla/myfile.js:14 throw err; ^ Error: I/O
error during "open" operation for file "/Users/bla/mydb.FDB", Error
while trying to open file at doCallback
(/Users/bla/node_modules/node-firebird/lib/index.js:1233:18) at
/Users/bla/node_modules/node-firebird/lib/index.js:2897:21 at
/Users/bla/node_modules/node-firebird/lib/messages.js:151:25 at search
(/Users/bla/node_modules/node-firebird/lib/messages.js:117:13) at
/Users/bla/node_modules/node-firebird/lib/messages.js:54:21 at
FSReqWrap.wrapper as oncomplete
NOTE:
Actually, I can connect the same database with c++ based driver:
var fb = require("firebird");
var con = fb.createConnection();
con.connectSync('mydb.FDB', 'SYSDBA', 'masterkey', '');
var rs = con.querySync('SOME QUERY');
And when I am trying to connect via Flamerobin, it works perfectly as well. This is really weird error I guess. Any other suggestions, please?

I don't know the node-firebird driver, but given the behavior, one might be connecting locally (with the client library acting as a server), while the other connects through the server. This could potentially lead to the following problems:
Different path resolution as you are specifying a relative path (unless mydb.FDB is defined as an alias), possibly the file /Users/bla/mydb.FDB doesn't exist
Insufficient access rights, the path /Users/bla/mydb.FDB in the error suggests it is a database in a user folder which means that it is not accessible to the Firebird server process (which usually runs under the user firebird).

Related

MongoError - Authentication error (password with #)

Here is my code in my NodeJS application, to connect to my MongoDB engine :
const collection = 'mynewcollection';
const password = 'passwordwithan#';
const mongoUrl = `mongodb://admin:${encodeURIComponent(password)}#mymongobase.net/${collection}`;
// Connect using the connection string
MongoClient.connect(mongoUrl, {useNewUrlParser: true}, function(err, db) {
console.log(err.toString())
});
I get an authentication error. I tried several things to handle the '#' character and reading the documentation I thought that it was the good one...
But it is still failing even if the user and password are the good one.
Is the API correctly used ? Do you understand what is wrong ?
Thanks in advance.
OK I found the solution.
If you use :
const mongoUrl = `mongodb://admin:${encodeURIComponent(password)}#mymongobase.net/${collection}`;
Mongo will try to connect with admin/password defined on the collection.
If you don't put the collection in the mongo url :
const mongoUrl = `mongodb://admin:${encodeURIComponent(password)}#mymongobase.net`;
Then you can use the super user defined on all the mongo engine.

Riak connectivity from Node

this is probably not a bug but rather a gap in my understanding but putting it here as afraid havent been able to find a way so far. Appreciate if you can provide your inputs please.
I'm trying to connect to my Riak cluster (hosted on AWS) of 3 nodes via two options - 1) Using an ejabberd server, and 2) using a Node server.
Connecting from the ejabberd server is successful after I put the hostname and port in the ejabberd configuration, but when I use a simple Node server (code below), I get the "Error: No RiakNodes available to execute command." error. Am I missing out on something here please - I can confirm that the 3 nodes are indeed up with Riak running? Note that if I dont do the client ping on the nodes, the server doesnt throw any error, so it is probably got to do with how pings are handled. The same server (without the ping) gives an ECONNREFUSED error if one of the nodes are brought down. So clearly the connection is going through but not the ping.
Apologize if am missing out on something basic here ... even the firewall settings for the Riak nodes have been set to all inbound, so it is not a case of the ejabberd server having access but not the Node server.
var async = require('async');
var assert = require('assert');
var logger = require('winston');
var Riak = require('basho-riak-client');
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {
level : 'debug',
colorize : true,
timestamp : true
});
var nodes = [
'ip-xx-xx-xx-xx:8087',
'ip-xx-xx-xx-xx:8087',
'ip-xx-xx-xx-xx:8087'
];
var client = new Riak.Client(nodes, function (err, c) {
logger.info('Now inside Riak.Client');
// NB: at this point the client is fully initialized, and
// 'client' and 'c' are the same object
});
client.ping(function (err, rslt) {
logger.info('Now entered client.ping');
if (err) {
logger.info('There is an error encountered in client.ping');
throw new Error(err);
} else {
// On success, ping returns true
logger.info('client.ping has resulted in success!');
assert(rslt === true);
}
});

Create a connection to the mongodb if connection is not established

I am new to node.js and mongoose.
I am trying to check whether a database with supplied name exists or not,
if exists,
establish a connection and use the same.
if not,
then create database with some collections.
I am using mongoose, as mongoose is providing 3 methods to establish the connection. i am unable to figure out which is the best suite for me and how to deal with them.
connect
createConnection
connection
By googling i got succeed in figuring out whether the DB name exists or not using createConnection.
var Admin = mongoose.mongo.Admin;
var dbName='test';
/// create a connection to the DB
var connection = mongoose.createConnection('mongodb://localhost/' +dbName );
connection.on('open', function () {
// connection established
new Admin(connection.db).listDatabases(function (err, result) {
console.log('listDatabases succeeded');
for (var i in result.databases) {
if (result.databases[i].name == dbName) {
mongoose.connect('mongodb://localhost/' + dbName);
next();
break;
}
}
});
});
I wrote the above code in route interceptor, so for every request the above code will be executed and trying to connect to mongodb if the given db name already exists.
Any help would be greatly appreciable..

Deploying Node/Mongo to Openshift

Hello I'm trying to get Node/Mongo service going on Openshift, here's what it looks like:
var db = new mongodb.Db('myServiceName',
new mongodb.Server('mongodb://$OPENSHIFT_MONGODB_DB_HOST','$OPENSHIFT_MONGODB_DB_PORT', {}));
db.open(function (err, db_p) {
if (err) { throw err; }
db.authenticate('$USER', '$PASS', function (err, replies) {
if (err) { throw err; }
// should be connected and authenticated.
// ...
The app was created using rhc:
$ rhc create-app myServiceName nodejs-0.10 mongodb-2.4
The console shows the app was started and is running, and on cURL the response is 503
My logs don't show an error, however, the dB is obviously not live. Can anyone help?
If your mongodb driver supports connection with username/password, then use OPENSHIFT_MONGODB_DB_URL instead of OPENSHIFT_MONGODB_DB_HOST
OPENSHIFT_MONGODB_DB_URL gives you this format:
mongodb://admin:password#127.4.99.1:27017/
and OPENSHIFT_MONGODB_DB_HOST gives you this format:
ip addres, ex: 127.4.99.1
So you can just use OPENSHIFT_MONGODB_DB_URL to connect and authenticate at the same time
with mongoskin, you can just do this:
var db = require('mongoskin').db(process.env.OPENSHIFT_MONGODB_DB_URL + 'dbname'+ '?auto_reconnect=true',
{safe: true, strict: false}
);
It looks like you are attempting to connect to a server named "$OPENSHIFT_MONGODB_DB_HOST", (not a valid URL).
Instead, you'll probably want to read the value of the OPENSHIFT_MONGODB_DB_HOST environment variable to find your connection information:
process.env.OPENSHIFT_MONGODB_DB_HOST
I have some additional notes up here: https://www.openshift.com/blogs/getting-started-with-mongodb-on-nodejs-on-openshift

Node.js and node-sqlanywhere - No Connection Available

I have been trying to use node-sqlanywhere to query my Sybase database.
However, I cannot seem to be able to connect to the database.
var sqlanywhere = require('sqlanywhere');
var sqlanywhere_conn = sqlanywhere.createConnection();
var sqlanywhere_conn_params = {
DatabaseFile: 'C:\Users\support\Dropbox\database.db',
AutoStart: 'YES',
UserId: 'user_id',
Password: 'password'
};
sqlanywhere_conn.connect(sqlanywhere_conn_params, function(){
sqlanywhere_conn.prepare('SELECT * FROM some_table WHERE some_column = ?', function (err, stmt){
if (err) throw err;
// do something with the statement
});
});
Whether I am trying to connect to the database using Server attribute or the DatabaseFile attribute, I always get error code -2005 No Connection Available.
That being said, I am able to connect to my database using Interactive SQL by either specifying the server or the database file.
So.. I must be missing something here and I can't figure it out !
Thanks !!
Try doubling up the backslash characters, like DatabaseFile: 'C:\\Users\\support\\Dropbox\\database.db'.
FYI you can also ask SQL Anywhere-specific questions on http://sqlanywhere-forum.sap.com.
Full disclosure: I work for SAP in SQL Anywhere engineering. I am responsible for both the node.js driver and the sqlanywhere-forum.sap.com site.

Resources