我可以通过命令行在 Windows 中创建 Snowflake ODBC DSN 吗?

发布于 2025-01-15 06:40:25 字数 2537 浏览 3 评论 0原文

我正在尝试通过命令行(包含在脚本中)使用 Windows 10 中的 Snowflake ODBC 驱动程序创建 64 位 ODBC 数据源。使用命令行工具(例如 odbcconf.exe)或 PowerShell cmdlet(例如 Add-OdbcDsn)是否可以实现这一点?如果可以,任何人都可以提供有效的示例吗?他们用来这样做的语法?

我过去曾使用其他 ODBC 驱动程序成功完成此操作,例如:

通过 odbcconf.exe 的 Oracle Instant Client:

C:\Windows\System32\odbcconf.exe /A {CONFIGSYSDSN "Oracle in instantclient64" "DSN=Example_DSN|Server=Example_Server"}

通过 Add-OdbcDsn 的 SQL Server:

Add-OdbcDsn -Name "Example_DSN" -DriverName "SQL Server" -DsnType "System" -Platform "32-bit" -SetPropertyValue @("Server=Example_Server","Trusted_Connection=Yes","Database=Example_Database")

但是,我一直在使用 Snowflake ODBC 驱动程序使用类似命令创建 DSN 时未成功。

我使用以下文章作为指导: https://docs.snowflake .com/en/user-guide/odbc-windows.html

作为参考,我可以通过“ODBC 数据源管理器(64 位)” GUI 创建 DSN,方法是选择“SnowflakeDSIIDriver” 驱动程序,并在“Snowflake 配置对话框” 窗口中填写数据源、用户和服务器属性,因此我知道可以使用此驱动程序创建 DSN ;我只是不知道如何通过命令行来做到这一点。

如果使用这些odbcconf.exe命令:

C:\Windows\System32\odbcconf.exe /A {CONFIGSYSDSN "SnowflakeDSIIDriver" "DSN=Example_DSN"}

C:\Windows\System32\odbcconf.exe /A {CONFIGSYSDSN "SnowflakeDSIIDriver" "DSN=Example_DSN|Server=EXAMPLE.us-east-1.snowflakecomputing.com Database=Example_Database Schema=Example_Schema Warehouse=Example_WH Role=Example_Role Tracing=4 Authenticator=externalbrowser"}

“雪花配置对话框”窗口将弹出,而不是创建 DSN,就像我尝试创建 DSN 一样通过“ODBC 数据源管理器(64 位)” GUI。仅“数据源”字段填充有我在“DSN=”之后放置的值。无论我尝试在命令中传递多少附加属性,所有其他字段都是空白的:

雪花配置对话框< /a>

如果我在弹出对话框时手动添加用户和服务器,然后单击“确定”,则会创建 DSN;但是,我也收到一条错误消息(如果我也在对话框窗口上选择“取消”,我也会收到同样的错误):

“CONFIGSYSDSN:无法为“SnowflakeDSIIDriver”驱动程序创建数据源:驱动程序的 ConfigDSN、ConfigDriver 或 ConfigTranslator 失败,错误代码为 -2147467259。”

(显然,这并不能解决问题,因为我的意图是仅使用该命令来创建 DSN,而无需用户交互。)

对于通过 PowerShell 的 Add-OdbcDsn

Add-OdbcDsn -Name "Example_DSN" -DriverName "SnowflakeDSIIDriver" -DsnType "System" -Platform "64-bit"

该命令似乎无限期地挂起,直到我取消它。我从未看到任何可见的错误消息,并且我没有看到“雪花配置对话框”窗口。

有没有人有任何我可以尝试的建议,和/或有人确定这是否可行,或者 Snowflake ODBC 驱动程序是否根本不支持它?

I am trying to create a 64-bit ODBC data source using the Snowflake ODBC driver in Windows 10 via the command line (for inclusion in a script). Is this possible using either a command-line tool such as odbcconf.exe or a PowerShell cmdlet such as Add-OdbcDsn, and if so, could anybody provide an example of valid syntax they have used to do so?

I have done this successfully in the past with other ODBC drivers, such as:

Oracle Instant Client via odbcconf.exe:

C:\Windows\System32\odbcconf.exe /A {CONFIGSYSDSN "Oracle in instantclient64" "DSN=Example_DSN|Server=Example_Server"}

SQL Server via Add-OdbcDsn:

Add-OdbcDsn -Name "Example_DSN" -DriverName "SQL Server" -DsnType "System" -Platform "32-bit" -SetPropertyValue @("Server=Example_Server","Trusted_Connection=Yes","Database=Example_Database")

However, I have been unsuccessful in using similar commands to create a DSN using the Snowflake ODBC driver.

I am using the following article for guidance: https://docs.snowflake.com/en/user-guide/odbc-windows.html

For reference, I can create a DSN via the "ODBC Data Source Administrator (64-bit)" GUI by selecting the "SnowflakeDSIIDriver" driver and filling in the data source, user, and server attributes in the "Snowflake Configuration Dialog" window, so I know it's possible create a DSN using this driver; I just can't figure out how to do it via the command line.

In the case of either of these odbcconf.exe commands:

C:\Windows\System32\odbcconf.exe /A {CONFIGSYSDSN "SnowflakeDSIIDriver" "DSN=Example_DSN"}

C:\Windows\System32\odbcconf.exe /A {CONFIGSYSDSN "SnowflakeDSIIDriver" "DSN=Example_DSN|Server=EXAMPLE.us-east-1.snowflakecomputing.com Database=Example_Database Schema=Example_Schema Warehouse=Example_WH Role=Example_Role Tracing=4 Authenticator=externalbrowser"}

Instead of creating the DSN, the "Snowflake Configuration Dialog" windows pops up as if I had attempted to create the DSN via the "ODBC Data Source Administrator (64-bit)" GUI. Only the "Data source" field is populated with the value I placed after "DSN=". All other fields are blank, regardless of how many additional attributes I try to pass in the command:

Snowflake Configuration Dialog

If I add the user and server manually when the dialog window pops up and then click "OK," the DSN does get created; however, I do also receive an error message (I get this same error if I select "cancel" on the dialog window as well):

"CONFIGSYSDSN: Unable to create a data source for the 'SnowflakeDSIIDriver' driver: Driver's ConfigDSN, ConfigDriver, or ConfigTranslator failed with error code -2147467259."

(Obviously, this doesn't solve the problem, as my intent would be for the command alone to create the DSN without user interaction.)

In the case of Add-OdbcDsn via PowerShell:

Add-OdbcDsn -Name "Example_DSN" -DriverName "SnowflakeDSIIDriver" -DsnType "System" -Platform "64-bit"

The command just seems to hang indefinitely until I cancel it. I never see any visible error messages, and I don't get the "Snowflake Configuration Dialog" window.

Does anybody have any suggestions I could try, and/or does anybody know for sure whether this is possible or if it's simply not supported by the Snowflake ODBC driver?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不忘初心 2025-01-22 06:40:25

是的,您可以执行此操作,但必须使用注册表项定义 Snowflake 驱动程序配置。

上面的答案是正确的,但对解决方案的描述性并不强。他们让我能够在 Powershell 中编写此脚本。

问题:

  1. 当尝试使用 Powershell 命令“Add-OdbcDsn”配置雪花 DSN 时,命令挂起并且永远不会完成(我的猜测是配置窗口静默打开并等待输入信息)。
  2. ODBCCONF.EXE(ODBCCONF [开关] 操作)失败,说明操作无效。

解决方案:
这是一个适合我的完整解决方案(专门在 Windows 10 上使用驱动程序 Snowflake64_odbc-3.2.0 进行了测试)。它使用注册表来配置 ODBC 用户 DSN,但可以针对系统 DSN 进行修改。

说明:以编程方式为 Windows 实例配置 Snowflake ODCB DNS

先决条件:安装 Snowflake 驱动程序 (SnowflakeDSIIDriver)。可以从 Snowflake HKCU 下载

:\SOFTWARE\ODBC\ODBC.INI\Snowflake 是配置用户 DSN 的注册表路径
HKLM:\SOFTWARE\ODBC\ODBC.INI\Snowflake 是配置系统 DSN 的注册表路径

如果不存在则需要创建该路径

  • New-Item -Path 'HKCU:\SOFTWARE\ODBC\ODBC.INI \雪花' | out-null

这些是对 Snowflake DSN 配置的响应

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -name "UID" -value %user_name% | out-null输出为空

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -name "SERVER" -value "%server_name.snowflakecomputing.com%" |输出为空

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -名称“DATABASE”-值“%data_base%”|输出为空

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -名称“SCHEMA”-值“%schema%”|输出为空

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -名称“WAREHOUSE”-值“%warehouse%”|输出为空

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -名称“TRACING”-值“%number%”|输出为空

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -name "AUTHENTICATOR" -value "%authenticator%"

这是配置到 DSN 的映射

  • new-itemproperty -path 'HKCU:\ SOFTWARE\ODBC\ODBC.INI\ODBC 数据源的-名称“Snowflake”-值“SnowflakeDSIIDriver”| out-null

注意:用 %value% 替换您的值。注册表项是 REG_SZ(字符串值),名称区分大小写。如果删除 ODBC DSN,则注册表项将被删除。

执行后,您可以通过启动 ODBC 并检查/测试配置来验证配置。

Yes, you can do this but the Snowflake driver configurations must be defined using registry keys.

The answers above are correct but not very descriptive on the solution. They led me to be able to script this in Powershell.

Issues:

  1. When attempting to use Powershell command "Add-OdbcDsn" to configure the snowflake DSN the command hangs and will never complete (my guess is that the configuration windows opens silently and is waiting for information to be input).
  2. ODBCCONF.EXE (ODBCCONF [switches] action) fails stating invalid actions.

Solution:
Here is a full solution that worked for me (specifically tested on Windows 10 with driver snowflake64_odbc-3.2.0). It uses the registry to configure the ODBC User DSN but could be modified for a System DSN.

Description: Programmatically configure Snowflake ODCB DNS for Windows instance

Prerequisite: Install Snowflake Driver (SnowflakeDSIIDriver). This can be downloaded from Snowflake

HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake is the registry path where the User DSN is configured
HKLM:\SOFTWARE\ODBC\ODBC.INI\Snowflake is the registry path where the System DSN is configured

This path needs to be created if it doesn't exist

  • New-Item -Path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' | out-null

These are the responses to the Snowflake DSN configuration

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -name "UID" -value %user_name% | out-null

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -name "SERVER" -value "%server_name.snowflakecomputing.com%" | out-null

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -name "DATABASE" -value "%data_base%" | out-null

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -name "SCHEMA" -value "%schema%" | out-null

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -name "WAREHOUSE" -value "%warehouse%" | out-null

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -name "TRACING" -value "%number%" | out-null

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\Snowflake' -name "AUTHENTICATOR" -value "%authenticator%"

This is the mapping for the configuration to the DSN

  • new-itemproperty -path 'HKCU:\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources' -name "Snowflake" -value "SnowflakeDSIIDriver" | out-null

Note: Substitute %value% for your values. The registry keys are REG_SZ (String Values) and the -names are case sensitive. If you delete the ODBC DSN then the registry entries will be removed.

Once executed you can verify configuration by launching ODBC and checking/testing the configuration.

秋凉 2025-01-22 06:40:25

不是完整的解决方案,而是 文档 提及注册表设置位置。因此,您可以手动完成,然后“读取”注册表设置集,然后将它们注入脚本中。

Not a full solution, but the Doc's mention the registry settings location. So you could manually complete, and then "read" the registry settings set, and then inject those in your scripts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文