I can't connect to snowflake using node js connector

别等时光非礼了梦想. 提交于 2021-02-11 14:00:20

问题


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.


回答1:


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




回答2:


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




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/61115469/i-cant-connect-to-snowflake-using-node-js-connector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!