Search code examples
snowflake-cloud-data-platformhostnamesnowflake-task

How to resolve Invalid URI issue in C# while connecting to Snowflake?


I am trying to connect to Snowflake via azure function app. Following is the code snippet (ref: https://github.com/snowflakedb/snowflake-connector-net#create-a-connection ) I am using:

using (IDbConnection conn = new SnowflakeDbConnection())
{
    // Connect to Snowflake
    conn.ConnectionString = @"host = <Account_Name>;account = <Account_Name>;user = <User_name>;password = <password>;db = <my_DB>; schema = <My_SCHEMA>;";
    conn.Open();
}

As long as I understand: account here is nothing but first part of the URL i.e., bold part of the URL account.east-us-2.azure.snowflakecomputing.com

Is there anything wrong I'm doing here? When execution comes to conn.Open(); I am getting an error like :
Invalid URI: The hostname could not be parsed.
Correct me if I have any code error here.


Solution

  • For the account name, you need to omit the cloud provider and region. So instead of "account.east-us-2.azure" it should be only "account".

    Since this account is not in the US West deployment, you also must supply a "host" parameter, which does not appear in your connection string. The host should be "account.east-us-2.azure.snowflakecomputing.com"

    Here's a sample connection string:

    conn.ConnectionString = "account=accountname;host=accountname.east-us-2.azure.snowflakecomputing.com;user=myuser;password=*****;db=test;schema=public;warehouse=test";