Just been playing with node.js and trying to get it to connect to an SQLAnywhere database. The servers we have are a mix of 8.02 and 10. I know that the former is not supported, but PHP and v12 clients seem to have no trouble connecting.

The thing that baffles me is that the connection parameters used in examples seem strangely incomplete. Traditionally, I've always had to specify IP address, DB Server name, DB Name, UserID and Password. Most of the examples seem to suggest that server name and db name are not necessary. In which case, how does the code decide which database to connect to when a server is hosting several?!!!

I tried both: - unixodbc and FreeTDS (I got stuck with a "Can't find the specified Database" once I'd got the server coordinates correct) - sqlanywhere node module (I don't even know where to get any diagnostics - the code simply doesn't work!)

I wonder if anyone else has been here before!

asked 31 Oct '14, 18:26

thewinelake2's gravatar image

thewinelake2
1112
accept rate: 0%

So I can now see that I'm getting an error Error: Code: -2001 Msg: Invalid Object

var sqlanywhere = require('sqlanywhere');

var conn = sqlanywhere.createConnection();

var conn_params = { Server : 'm1009', DBN : 'dmcc_m1009', Host : '1.2.3.4', Port : '2638', Uid : 'dba', Pwd : 'sql' };

var err = conn.connect(conn_params, function() {

conn.exec('SELECT 0', function (err, result) {

  if (err) throw err;

  console.log(result);
})

});

(31 Oct '14, 18:56) thewinelake2

Does this mean you have figured this out or are you still stuck?

FreeTDS is not an SAP (nor a Sybase) feature and it will not Sybase-style TDS in all cases. You might want to try to see if switching to the PHP driver supplied with SQL Anywhere helps you out more.

I doubt that DBN will be respected if you continue to use FreeTDS. The concept required to map to the SQL Anywhere DBN, is that of "ServiceName" as it exists in JConnect or OpenClient, but you are using neither so (this not be available to you. Note this and dbn are also different from "Database=<database>" connection parameter in the FreeTDS ODBC implementation since that will map to a "USE <database>" statement that will just be ignored by SQL Anywhere so that approach is not an option either.

I recommend using either the SQL Anywhere PHP driver or to switch over to using ODBC and the native SQL Anywhere ODBC driver.

permanent link

answered 04 Nov '14, 13:28

Nick%20Elson%20SAP%20SQL%20Anywhere's gravatar image

Nick Elson S...
7.3k35107
accept rate: 31%

Re: Most of the examples seem to suggest that server name and db name are not necessary. In which case, how does the code decide which database to connect to when a server is hosting several?!!!

Defaults, defaults, defaults... For example, the port default is 2638, the database default is first database started, and so on.

So if there is any chance that you might not connect to the right server/database, then use connection parameters to get it right. But Port is not allowed in the hash. Use ip-addr:port in Host. For example (pardon the formatting):

var sqlanywhere = require('sqlanywhere');
var conn = sqlanywhere.createConnection();
var cstr = { Host : 'my-t3500:49152', Server : 'Demo16', 
    UserID : 'DBA', Password : 'sql', DatabaseName : 'sample' };
conn.connect(cstr, function( err ) {
    if( err ) {
        console.log( err );
        return;
    }
    console.log( "Connected." );

    conn.exec( "SELECT DB_NAME()", function(err, result) {
        if ( err ) {
            console.log( err );
            return;
        }
        console.log( "Result: ", result );
    });

    conn.disconnect( function( err ) {
    console.log( "Disconnected." );
});

});

permanent link

answered 06 Nov '14, 12:09

JBSchueler's gravatar image

JBSchueler
2.0k2837
accept rate: 15%

Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

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:

×13

question asked: 31 Oct '14, 18:26

question was seen: 5,226 times

last updated: 06 Nov '14, 12:09