使用Golang SQL驱动程序连接到Snowflake

huangapple go评论79阅读模式
英文:

Connecting to Snowflake using Golang SQL driver

问题

我一直在尝试使用Snowflake的Golang驱动程序连接到Snowflake。以下是我的代码:

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)

我遇到的问题是,在连接后,我尝试发送给Snowflake的每个命令都返回以下错误:

gosnowflake.(*defaultLogger).Errorln Authentication FAILED

如果我将账户更改为fmt.Sprintf("%s.%s", organization, account),这个错误就消失了,但是,如果我尝试使用连接进行查询,我会得到以下错误:

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.

根据这个这个,账户标识符应该等于{ORGANIZATION_NAME}-{ACCOUNT_NAME},而我的确是这样设置的。此外,我使用了SHOW ORGANIZATION ACCOUNTS命令来验证组织名称和账户名称是否正确。

英文:

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.

答案1

得分: 0

问题是,我尝试查询的用户实际上没有访问数据库、模式和表的权限。我可以通过使用该用户的帐户登录到Snowflake控制台,然后查看“数据”页面来确认这一点。当我这样做时,我注意到数据库没有显示出来。

进一步调查后,我注意到数据库是由ACCOUNTADMIN角色拥有的,而我的用户没有这个角色。因此,我将数据库的所有权转移到了SYSADMIN角色,而我的用户具有该角色。然后,我对与数据库相关的模式和表执行了相同的操作。

完成这些操作后,问题消失了。

英文:

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.

huangapple
  • 本文由 发表于 2022年8月2日 15:01:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/73203245.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定