dotConnect for Snowflake Documentation
Devart.Data.Snowflake Namespace / SnowflakeConnection Class
Members Example

On this page
    SnowflakeConnection Class
    On this page
    Represents an open connection to Snowflake.
    Syntax
    Remarks

    A SnowflakeConnection object represents a unique connection to Snowflake. Use it in conjunction with SnowflakeCommand, SnowflakeDataReader, SnowflakeDataAdapter or other components for convenient interoperation with Snowflake.

    When you create an instance of SnowflakeConnection, all properties are set to their initial values. For a list of these values, see ConnectionString.

    If the SnowflakeConnection goes out of scope, it is not closed. Therefore, you must explicitly close the connection by calling Devart.Common.DbConnectionBase.Close.

    Note that SnowflakeConnection instance is not guaranteed to be thread safe. You should avoid using the same SnowflakeConnection in several threads at the same time. It is recommended to open a new connection per thread and to close it when the work is done. Actually, connections will not be created/disposed every time with the Pooling=true; connection string option - connections will be stored at connection pool. This boosts performance greatly.

    A single SnowflakeConnection can be used by many SnowflakeCommand objects on the assumption that all operations will be done consecutively. In other words, you can not execute a SQL statement while an asynchronous operation is in progress.

    Example
    The following example creates a SnowflakeCommand and a SnowflakeConnection. The SnowflakeConnection is opened and set as the Connection property. The example then calls ExecuteNonQuery method, and closes the connection. To accomplish this, the ExecuteNonQuery is passed a connection string and a query string that is SQL INSERT statement.
    public void InsertRow(string snowflakeConnectionString)
    {
      // If the connection string is empty, use default.
      if(snowflakeConnectionString == "")
      {
        snowflakeConnectionString = 
            "Domain=myorg-myaccount.snowflakecomputing.com;User=your_user;Password=********;Database=your_database;Schema=your_schema;Warehouse=your_warehouse;License Key=**********";
      }
      SnowflakeConnection myConn = new SnowflakeConnection(snowflakeConnectionString);
      string myInsertQuery = "INSERT INTO your_database.your_schema.employees (first_name, last_name) VALUES ('John', 'Smith')";
      SnowflakeCommand snowflakeCommand = new SnowflakeCommand(myInsertQuery);
      snowflakeCommand.Connection = myConn;
      myConn.Open();
      try
      {
        snowflakeCommand.ExecuteNonQuery();
      }
      finally
      {
        myConn.Close();
      }
    }
    Public Sub InsertRow(snowflakeConnectionString As String)
      ' If the connection string is empty, use default.
      If snowflakeConnectionString = "" Then
        snowflakeConnectionString = _
            "Domain=myorg-myaccount.snowflakecomputing.com;User=your_user;Password=********;Database=your_database;Schema=your_schema;Warehouse=your_warehouse;License Key=**********"
      End If
      Dim myConn As New SnowflakeConnection(snowflakeConnectionString)
      Dim myInsertQuery As String = "INSERT INTO your_database.your_schema.employees (first_name, last_name) VALUES ('John', 'Smith')"
      Dim snowflakeCommand As New SnowflakeCommand(myInsertQuery)
      snowflakeCommand.Connection = myConn
      myConn.Open()
      Try
        snowflakeCommand.ExecuteNonQuery()
      Finally
        myConn.Close()
      End Try
    End Sub
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.ComponentModel.Component
             System.Data.Common.DbConnection
                Devart.Common.DbConnectionBase
                   Devart.Data.SqlShimConnection
                      Devart.Data.Snowflake.SnowflakeConnection

    See Also