问题描述
我正在尝试创建连接字符串,以从Access 2010及更高版本访问Snowflake数据。我可以创建数据库DSN并链接到我使用的表,但我需要为分布式应用程序构建无DSN的连接字符串。以下是我到目前为止所得到的,它失败了,并显示消息"ODBC连接到xxxx失败"。以下是我到目前为止的情况:
ODBC;驱动程序={SnowflkeDSIIDriver};服务器=https://server名称;角色=角色名称;仓库=仓库名称;数据库=数据库名称;架构=架构名称;UID=雪花ID;PWD=雪花密码;
推荐答案
我可以确认无域名系统的连接在Access 2013中工作正常。我还没有在Access 2010上进行测试,但如果需要测试,我会提供它。
我遇到的第一个问题是,Snowflake ODBC驱动程序在控制面板的ODBC部分报告32/64-bit
,但它可能没有安装其中一个。
在我的情况下,它在DSN源中显示为32/64-bit
,但我只安装了64位版本。请注意,安装32位驱动程序后,程序和功能(卸载应用程序的正常位置)将同时显示64位和32位驱动程序。
安装32位驱动程序后,只需获得正确的连接字符串即可。您想要从Snowflake Web用户界面上的URL复制它。去掉https://
部分,然后保留URL中的所有内容,包括snowflakecomputing.com
。这将用于server
。
编辑2:我错过了问题中提到传递查询的部分,而是描述了我最近使用VBA测试的无DNS连接的过程。我测试了直通连接,它工作正常。唯一的区别是在ODBC连接字符串中需要保留前缀:
ODBC;Driver{SnowflakeDSIIDriver};server=<your_URL_everything_before_snowflakecomputing.com>.snowflakecomputing.com;uid=greg;pwd=xxxxxx
编辑:我忘记了一件事,现在正在添加...内置的Access数据引擎无法让我使用无域名系统的连接方式进行连接。代码显示它使用的是ActiveX数据对象(ADO)。您需要在VBA项目中添加对它的引用:
' For the account, use everything after https:// up to and including
' snowflakecomputing.com in your URL when connecting to Snowflake using the web UI.
Const SNOWFLAKE_ACCOUNT = "<your_account>.<your_region>.snowflakecomputing.com"
Const SNOWFLAKE_USER = "greg"
Const SNOWFLAKE_PASSWORD = "xxxxx"
Public Sub Main()
Dim odbc As String
Dim sfCon As ADODB.Connection
Set sfCon = OpenDatabaseConnection(GetConnectionString())
If Not sfCon Is Nothing Then
'Use the connection here...
sfCon.Close
End If
End Sub
Private Function GetConnectionString()
GetConnectionString = "Driver={SnowflakeDSIIDriver}" + _
";server=" + SNOWFLAKE_ACCOUNT + _
";uid=" + SNOWFLAKE_USER + _
";pwd=" + SNOWFLAKE_PASSWORD + _
";network_timeout=60" + _
"login_timeout=60"
End Function
Public Function OpenDatabaseConnection(ConnString As String) As ADODB.Connection
On Error GoTo Handler
Dim database As ADODB.Connection
Set database = New ADODB.Connection
With database
.ConnectionString = ConnString
.ConnectionTimeout = 60
.Open
End With
Set OpenDatabaseConnection = database
Exit Function
Handler:
MsgBox "Error: " + Err.Description
End Function