Search code examples
c#connectionsnowflake-cloud-data-platform.net-6.0snowflake-connector

.NET 6 C# Getting timeout attempting to connect to Snowflake database


Every time I try to connect to a snowflake database in .NET 6 using the Snowflake.Data NuGet package, I get a timeout after 120 seconds. I've tried it with all correct credentials in the connection string, as well as all incorrect credentials. No matter what the response is the same:

[2022-06-26T21:05:06.742Z] Snowflake.Data.Client.SnowflakeDbException (0x80004005): Error: Snowflake Internal Error: Unable to connect SqlState: 08006, VendorCode: 270001, QueryId:
[2022-06-26T21:05:06.743Z]  ---> System.AggregateException: One or more errors occurred. (Error: Request reach its timeout. SqlState: , VendorCode: 270007, QueryId: )

My code setup looks like this to connect:

using (var conn = new SnowflakeDbConnection())
            {
                conn.ConnectionString = @"
                    ACCOUNT=<account>;
                    USER=<user>;
                    PASSWORD=<password>;
                    ROLE=<role>;
                    DB=<db>;
                    WAREHOUSE=<warehouse>";

                _log.Information("Attempting connection to Snowflake...");
                await conn.OpenAsync();
...

Every time after attempting to open the connection it hangs for 120 seconds then produces the above error. I've tried async and non-async as well as a bunch of different connection string properties. I also verified I was able to establish an outbound connection to another database with a regular SqlConnection and that worked with no issues. Not sure what could be going wrong.

Also ran the Snowcd connection diagnostic tool as descripted in the docs, results were all passing: snowcd diagnostic results


Solution

  • After much trial and error, adding the specific HOST value to the connection string was what fixed it for me. Specifying the full account with region for the ACCOUNT value did not work. Only when done under HOST. Although the GitHub documentation states that HOST is not required, specifying it with the region is the only thing that prevented timeouts on my end.