cancel
Showing results for 
Search instead for 
Did you mean: 

Getting started with node and SQLAnywhere

Former Member
0 Kudos
9,300

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!

Accepted Solutions (0)

Answers (2)

Answers (2)

jack_schueler
Product and Topic Expert
Product and Topic Expert

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." );
});


});

Former Member

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.