I'm trying to connect to a remote Sql Anywhere 12.01 database with the following code:

let sqlanywhere = require('sqlanywhere');

        let conn = sqlanywhere.createConnection();

        let conn_params = {
            Server : 'server:port',
            UserId : 'user',
            Password : 'pass'

        conn.connect(conn_params, function() {
            conn.exec('select * from cases', function (err, result) {
                if (err) {
                } else {


My console.log("Connected!") fires so I'm assuming that I've connected to the remote database? However, any query that I make results in this:

[Error: Code: -2001 Msg: Invalid Object]

I looked through the error codes online and didn't find this one. Anyone know why I may be experiencing it and how I can fix it?

asked 23 Sep '15, 18:33

swappticon's gravatar image

accept rate: 0%

edited 23 Sep '15, 18:38

FWIW, as v17 has official Node.js support, you might have a look at the samples there, cf. Node.js application programming and the following pages.

(24 Sep '15, 09:23) Volker Barth
Replies hidden

Cool, I didn't know there was official support! I assume that, although the official support is for v17, I may be able to get it working with v12.01?

(24 Sep '15, 10:01) swappticon

The callback function should take two parameters: err and result. If err is undefined, then the connection succeeded, otherwise it indicates what error occurred. (In the case of connection, result will always be undefined.) Your code should look like this:

conn.connect( conn_params, function( err, result ) {
   if( err ) {
      console.log( "Connection failed: "+err );
   } else {
      console.log( "Connected!" );

I had to change "let" to "var" to make the javascript run. Also, your Server connection parameter should be the server name, not the location. You should change "Server" to "Host" to indicate the hostname / port.

permanent link

answered 24 Sep '15, 08:56

Graeme%20Perrow's gravatar image

Graeme Perrow
accept rate: 54%

edited 24 Sep '15, 12:57

Ahh I wondered about the initially.. I wasn't sure if the callback took any parameters. I just tried it with the parameters and I am now getting a new error:

[Error: Code: -2004 Msg: Can't initialize DBCAPI]

Any idea what's going on there? This is the error that's returned from the conn.connect function

(24 Sep '15, 10:02) swappticon
Replies hidden

Do you have the SQL Anywhere client software installed? dbcapi is part of that, and the node.js driver needs it.

(24 Sep '15, 10:11) Graeme Perrow

I am not sure. What client software are you referring to? I originally tried installing the Sql Anywhere ODBC client but ran into some problems and decided to give the node module a try.

(24 Sep '15, 11:41) swappticon
Replies hidden

The SQL Anywhere ODBC client would contain the files needed by the node.js driver. Did you run into problems installing it or using it? Is it still installed?

(24 Sep '15, 11:46) Graeme Perrow

Ahh nvm. I just installed the client software and the sourced it. I forgot to run the source command when I did it earlier. I still haven't gotten the code to work, but I'm getting a database server not found error so maybe my code isn't the problem and it has more to do with the IP:Port I was given.

(24 Sep '15, 11:51) swappticon
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 23 Sep '15, 18:33

question was seen: 2,360 times

last updated: 24 Sep '15, 12:57