ODBC connection string to Snowflake for Access Pass Thru Query
Asked Answered
T

2

8

I am trying to create a connection string to get to Snowflake data from Access 2010 and above. I can create a database DSN and link to the tables I use, but I need to build DSN-less connection strings for distributed applications. Here's what I have so far, it fails with the message "ODBC connection to xxxx failed". Here's what I have so far:

ODBC;Driver={SnowflakeDSIIDriver}; Server=https://server name; Role=role name;Warehouse=warehouse name;Database=db name;Schema=schema name;UID=snowflake ID; PWD=snowflake password;

Tallyman answered 30/4, 2020 at 21:14 Comment(5)
Server -- I think you may need to remove the "https://" piece. You can also test with a regular DSN first before making the connection string to make sure all the entries work.Christyna
Thanks for the reply, like I said, I can connect with a DSN - defined in Access in External Data - ODBC Database, I can attach to and query Snowflake tables. I don't want to distribute applications that require users to maintain DSN passwords, etc. I have tried without https:// in the server name, same error. It is trying to connect, it churns for 30 seconds or so. I have a feeling it might be how the Snowflake authentication is specified in the parameters.Tallyman
Understood. Hard to say what the issue is then; if the DSN is working then the same setup via connection string should behave similarly. This connection string should work (it looks right to me) with the default Snowflake authenticator, unless Access somehow does not support this. You could potentially test with another authenticator or another application. Most Driver Managers have tracing as well you can enable (or you can try looking at the logs generated from the ODBC driver for clues as well). community.snowflake.com/s/article/…Christyna
BrianHtx/Martijn Pieters - did you ever discover a solution? I'm struggling at the moment with a connection to snowflake and right now the main issue appears to be that the Passthrough ODBC connection string length is limited to 255 characters. I need it more space and am not sure how to 'get' it.Whence
@Whence Are you using ADO for the connection or what object library?Portative
C
4

I think you are on the right track. I have the same thing and it works.

ODBC;
driver={SnowflakeDSIIDriver};
server=accountname.snowflakecomputing.com;database=dbname;
schema=public;
warehouse=whname;
role=rlname;
Uid=userid;
Pwd=password;

Very odd that the DSN one works and your doesn't.

Clarisclarisa answered 18/7, 2020 at 5:2 Comment(0)
P
4

I can confirm that DNS-free connections work fine in Access 2013. I have not tested on Access 2010, but I have it available if that needs testing.

The first problem I encountered is that the Snowflake ODBC driver reports 32/64-bit in the ODBC section of Control Panel, but it may not have one or the other installed.

In my case, it showed in the DSN sources as 32/64-bit, but I had only the 64-bit version installed. Notice that after installing the 32-bit driver, the Programs and Features (where to go normally for uninstalling apps) shows both the 64 and 32 bit drivers.

enter image description here

After installing the 32-bit driver, it was just a matter of getting the connection string right. You want to copy it from the URL on your Snowflake web UI. Strip off the https:// part, and then keep everything up to and including the snowflakecomputing.com in the url. That's what you'll use for the server.

Edit 2: I missed the part of the question that referenced pass through queries and was describing a procedure I tested recently for DNS-free connection using VBA. I tested the pass-through connection and it worked fine. The only difference is in the ODBC connection string you need to keep the "ODBC;" prefix:

ODBC;Driver{SnowflakeDSIIDriver};server=<your_URL_everything_before_snowflakecomputing.com>.snowflakecomputing.com;uid=greg;pwd=xxxxxx

Edit: One thing I forgot and am adding... The built-in Access data engine did not work for me to connect with a DNS-free connection. The code shows that it's using ActiveX Data Objects (ADO). You need to add a reference to that in your VBA project:

enter image description here

enter image description here

' 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
Portative answered 8/10, 2021 at 17:8 Comment(7)
Greg Pavlik - appreciate your taking the time to provide a detailed answer here. Unfortunately, this isn't exactly what I was looking for but am hoping you may have created pass through queries with your instance of Snowflake. As the OP had originally asked, and what I'm looking for: what is the proper format for the ODBC Connection string property of a pass through query. Would you be able to help with this?Whence
Hi JimT. I missed the "passthrough" part and was thinking VBA. I tested an ODBC DSN and it worked for me in Access 2013. Please see the updated update to the answer. Basically it's the same DNS as for VBA but keeps the ODBC; prefix.Portative
Thanks again Greg - I wonder if I don't have something configured correctly. So our company is using 64-bit office and I have the 64-bit Snowflake ODBC Driver (2.22.04). I am able to connect to the Snowflake database through my browser, but using the ODBC Connection string you provided doesn't appear to even 'try' to connect in MS Access but promptly returns "ODBC--call failed. Data source name not found and no default driver specified." Any thoughts here?Whence
I haven't tested in Office 64-bit. I'll use a clean VM and install Office 64 bit to test it. What version of office do you use?Portative
Thanks Greg - the company is using Microsoft 365 for enterprise.Whence
@JimT, I tested 64-bit office and was not able to get passthrough queries to work with DNS-free connections. I tried both the Snowflake and CData ODBC drivers. I set the ODBC trace logs and they didn't have anything helpful.Portative
Thanks Greg, I'm struggling as well (as are my company DBA's). I appreciate the effort that you put into it - it looks like you received +25 bounty?Whence

© 2022 - 2024 — McMap. All rights reserved.