0
votes

I'm trying to connect to snowflake database, using snowflake-sdk connector.

First I installed the snowflake-sdk, using the command line:

npm install snowflake-sdk

After I followed all the instructions reported here.

i created the file index.js containing:

    var snowflake = require('snowflake-sdk');
    var connection = snowflake.createConnection( {
        account : 'xxxx.east-us-2'
        username: 'MYUSERNAME'
        password: 'MYPASSWORD'
        }
        );
    connection.connect( 
        function(err, conn) {
            if (err) {
                console.error('Unable to connect: ' + err.message);
                } 
            else {
                console.log('Successfully connected to Snowflake.');            
                }
            }
        );

and after I run the command node index.js

and I had the Connection error:

Unable to connect: Network error. Could not reach Snowflake.

I Tried again, changing the account value in xxxx.east-us-2.azure.snowflakecomputing.com but nothing changed.

4

4 Answers

0
votes

Your account name should include cloud provider as well. Change the account name as :

var connection = snowflake.createConnection( {
    account : 'xxxx.east-us-2.azure'
    username: 'MYUSERNAME'
    password: 'MYPASSWORD'
    }

For full account names refer docs

0
votes

The issue is with your account name. Please pass your account name as xxxx.east-us-2.azure

0
votes

Here's the code I used in a tiny issue reproduction that I sent to the Snowflake support people.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const snowflake = require("snowflake-sdk");
const Q = require("q");
const SNOWFLAKE_HOST_SUFFIX = 'snowflakecomputing.com';    
const SNOWFLAKE_ACCOUNT = 'companyname';
function getSFConnection(connParams) {
    var d = Q.defer();
    let connection = snowflake.createConnection({
        account: connParams.account || SNOWFLAKE_ACCOUNT,
        username: connParams.user,
        password: connParams.password || '',
        database: connParams.name,
        warehouse: connParams.warehouse
    });
    connection.connect(function (err, conn) {
        if (err) {
            console.error('Unable to connect: ' + err.message);
            d.reject(err);
        }
        else {
            console.info('Successfully connected as id: ' + connection.getId());
            connection.close = function () {
                return disconnectSF(connection);
            };
            d.resolve(connection);
        }
    });
    return d.promise;
}

and I used it like:

getSFConnection({ 
    user: 'username',
    account: 'companyname',
    password: 'password',
    name: '',
    warehouse: 'warehouse_name'
}).then...

upon reflection I wonder why I have the host suffix set, but am not using it.. but there it is.

0
votes

Following is the right config for "snowflake-sdk": "^1.5.3"

var connection = snowflake.createConnection({
    account: 'xxx.us-east-1',
    username: 'yourUsername',
    password: 'yourPassword',
});

Do not specify the region.

region — Deprecated https://docs.snowflake.com/en/user-guide/nodejs-driver-use.html