0
votes

I am trying to connect my API to snowflake, using the node.js driver found in the snowflake documentation https://docs.snowflake.com/en/user-guide/nodejs-driver-use.html

const connection = snowflake.createConnection({
  account: process.env.SNOWFLAKE_ACCOUNT,
  username: process.env.SNOWFLAKE_USERNAME,
  password: process.env.SNOWFLAKE_PASSWORD,
})

connection.connect((err, conn) => {
  if (err) {
    console.error('Unable to connect: ' + err.message);
  } 
  else {
    console.log('Successfully connected to Snowflake.');
    const connection_ID = conn.getId();
    return connection_ID
  }
});

However, I am getting this error: Unable to connect: Network error. Could not reach Snowflake.

Not sure what I am missing. Would be great if someone could share some insights here? Thanks in advance!

3

3 Answers

0
votes

I'd recommend double checking what you have for SNOWACCT make sure it's set like the examples in https://docs.snowflake.com/en/user-guide/nodejs-driver-use.html#required-connection-options

The next thing I'd do is try to see if I could get SnowCD installed on the host(client) your node.js application is running from. SnowCD should help you determine what http/https resources you can't access, and then perhaps you can work with someone on your networking team to determine why your access isn't allowed (proxies, VPC rules, etc.). https://docs.snowflake.com/en/user-guide/snowcd.html

If you cannot install SnowCD, you can try to emulate the things it does, for example:

I hope this helps...Rich

p.s. If this (or another) answer helps you, please take a moment to "accept" the answer that helped by clicking on the check mark beside the answer to toggle it from "greyed out" to "filled in".

0
votes

See my answer on https://stackoverflow.com/a/65434455/1440712

Make sure your account is something like this xxx.us-east-1, region is now deprecated.

0
votes

If you want to connect a snowflake with node js, You must install

"snowflake-sdk"

using npm. the below code will help you to access snowflake connection.

const snowflake = require('snowflake-sdk');       
   connection = snowflake.createConnection({
      "account": "your account",
      "username": "user name",
      "password": "password",
      "database": "snowflake db",
      "warehouse": "snowflake warehouse",
      "schema": "schema"
    });connection.connect(function (err, conn) {
    if (err) {
      console.error('Unable to connect: ' + err.message);
    } else {
      console.log('Successfully connected as id: ' + connection.getId());
    }
  });