Skip to Content
avatar image
Former Member

XS Advanced - Node.js Module - HDB Connection Error

Hello everybody,

i try to establish a connection and send some queries to the HANA 2.0 express edition, running on my laptop. I've build a XS Advanced app and now i'm writing a Node.js module using the sap-hdbext and express modules to establish a connection to the HDB like so:

module.exports = function() {
	var app = express();


	passport.use("JWT", new xssec.JWTStrategy(xsenv.getServices({
		uaa: {
			tag: "xsuaa"
		}
	}).uaa));
	app.use(passport.initialize());


	app.use(
		passport.authenticate("JWT", {
			session: false
		}),
		xsHDBConn.middleware()
	);


	//Simple Database Select - In-line Callbacks
	app.route("/simptab")
		.get(function(req, res) {
			var client = req.db;
			client.prepare(
				"select Test from \"project.db.data::SimpleTable\" ",
				function(err, statement) {
					if (err) {
						res.type("text/plain").status(500).send("ERROR: " + error);
						return;
					}
					statement.exec([],
						function(err, results) {
							if (err) {
								res.type("text/plain").status(500).send("ERROR: " + err);
								return;
							} else {
								var result = JSON.stringify({
									Objects: results
								});
								res.type("application/json").status(200).send(result);
							}
						});
				});
		});

I've setup the package.json file and the server.js and everything else just like in the Dev Guide and openSAP course.

But if i go to the URL "https://hxehost:....../node/simptab" to access my node module the following error occurs:

Error: Could not connect to any host: [ undefined:NaN - connect ECONNREFUSED 127.0.0.1 ]   at couldNotOpenConnectionError (/hana/shared/HXE/xs/controller_data/executionagent/executionroot/f6e141e5-a900-460a-a8b9-9052ee21b55d/app/node_modules/hdb/lib/protocol/ConnectionManager.js:130:13)   at ConnectionManager._openConnectionToHost (/hana/shared/HXE/xs/controller_data/executionagent/executionroot/f6e141e5-a900-460a-a8b9-9052ee21b55d/app/node_modules/hdb/lib/protocol/ConnectionManager.js:43:15)   at /hana/shared/HXE/xs/controller_data/executionagent/executionroot/f6e141e5-a900-460a-a8b9-9052ee21b55d/app/node_modules/hdb/lib/protocol/ConnectionManager.js:56:10   at Socket.onerror (/hana/shared/HXE/xs/controller_data/executionagent/executionroot/f6e141e5-a900-460a-a8b9-9052ee21b55d/app/node_modules/hdb/lib/protocol/Connection.js:168:5)   at Socket.g (events.js:291:16)   at emitOne (events.js:96:13)   at Socket.emit (events.js:188:7)   at emitErrorNT (net.js:1276:8)   at _combinedTickCallback (internal/process/next_tick.js:74:11)   at process._tickCallback (internal/process/next_tick.js:98:9)

What could be the cause? I've tried nearly every i could come up with to solve this but nothing worked.

Like i said, i've setup everything just like in the demos.

Please help.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 03, 2017 at 10:03 AM

    Hi,

    it seems, several devs encountered the same issue ;) We solved it by changing a bit our node.js-Server.. So, try this also, if you wish!

    https://answers.sap.com/questions/119147/xs-advanced-nodejs-module-hdb-connection-error-con.html?childToView=120380#answer-120380

    (in short, you need to add options.hana to your xsHDBConn.middleware() ! Be sure to declare options first, as shown via the provided link)

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 02, 2017 at 07:46 AM

    Hi,

    From the error it seems HANA host and port are not properly configured.

    What is xsHDBConn and how do you initialize it?

    Make sure to use sap-hdbext and not sap-hdb-connection, which is deprecated.

    To check the actual parameters passed to your app you can use the command:

    xs env <app-name>

    Best regards,

    Petar

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 27 at 08:56 PM

    Hi All

    We are having the same exact problem in Cloud Application Program in Cloud Foundry with Hana 2.0. The app was working fine with CDS oData calls and it stopped working this week with this same exact error. Any help is much appreciated. We already implemented the above suggestions in our Server.js in node service.

    Thanks

    Sasi

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 09, 2017 at 02:55 PM
    -1

    Hi,

    thank you Sören. Your answer is the right solution. Since posting my issue here, i've discovered this solution by myself.

    I was confused by the videos of the openSAP course about HANA XS Advanced which never showed that these options have to be passed to the authentification module. I finally found the solution in the example project of the openSAP course.

    Best regards,

    René

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hey René,

      I'm glad to hear that :) I've encountered the same trouble with those videos as you did, so I left all of the SAP Tutorial stuff aside ;)

      KR,
      Sören