Connecting to Snowflake using Golang SQL driver

Viewed 107

I've been trying to connect to Snowflake using their Golang driver. Below you'll find my code:

config := gosnowflake.Config{
    Account:   fmt.Sprintf("%s-%s", organization, account),
    User:      username,
    Password:  password,
    Database:  database,
    Schema:    schema,
    Warehouse: warehouse,
}

connStr, err := gosnowflake.DSN(&config)
if err != nil {
    panic(err)
}


db, err := sql.Open("snowflake", connStr)
if err != nil {
    panic(err)
}

db.PingContext(ctx)

The problem I'm having is that every command I try to send to Snowflake after connecting returns the following error:

gosnowflake.(*defaultLogger).Errorln Authentication FAILED

If I change the account to be fmt.Sprintf("%s.%s", organization, account), this error goes away but, if I try to query with the connection, I get:

x509: certificate is valid for *.us-west-2.snowflakecomputing.com, *.us-west-2.aws.snowflakecomputing.com, *.global.snowflakecomputing.com, *.snowflakecomputing.com, *.prod1.us-west-2.aws.snowflakecomputing.com, *.prod2.us-west-2.aws.snowflakecomputing.com, not {MY_ORG_ID}.{MY_ACCT_ID}.snowflakecomputing.com.

According to this and this, the account identifier should be equal to {ORGANIZATION_NAME}-{ACCOUNT_NAME}, which mine is. Furthermore, I have used the SHOW ORGANIZATION ACCOUNTS command to verify that the organization name and account name are correct.

2 Answers

The issue was that the user I was trying to query with did not actually have access to the database, schema and tables. I could confirm this by logging in to the Snowflake console with the user's account and then looking at the "Data" page. When I did, I noticed that the database wasn't showing up.

Investigating further, I noticed that the database was owned by the ACCOUNTADMIN role, which my user didn't have. So, I transferred ownership of the database to the SYSADMIN role, which my user did have. Then, I did the same thing for the schemas and tables associated with the database.

After doing this, the problem went away.

Related