Search code examples
c#.net-coreodbcsnowflake-cloud-data-platform

How to write ODBC connection string for Snowflake


How can I write an ODBC connection string for Snowflake? I can't seem to figure it out. Below is the sample code I put together in .NET Core:

using System;
using System.Data.Odbc;

namespace SnowflakeTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            string connetionString = null;
            OdbcConnection cnn;
            connetionString = "Driver={SnowflakeDSIIDriver};Server=xxxxxxx.snowflakecomputing.com;Database=SNOWFLAKE_SAMPLE_DATA;User=xxxxxx;Password=xxxxxxxxx";
            cnn = new OdbcConnection(connetionString);

            try
            {
                cnn.Open();
                Console.Write("Connection Open ! ");
                cnn.Close();
            }
            catch (Exception ex)
            {
                Console.Write("Can not open connection ! " + ex.Message);
            }

            Console.ReadKey();
        }
    }
}

Solution

  • Here is how you can build an ODBC connection.

    1. Create a file on the desktop, called foo.udl. Double Click on it
    2. In the Provider tab, select `Microsoft OLE DB Provider for ODBC Drivers'
    3. In the Connection tab, click Use connection string, then the 'Build` button.
    4. Under Machine Data Source pick your driver, then fill out the rest (e.g. user & password).
    5. Then click OK.
    6. Open the file in Notepad and boom - there is your connection string.