dotConnect for Google BigQuery Documentation
Devart.Data.BigQuery Namespace / BigQueryConnection Class
Members Example

On this page
    BigQueryConnection Class
    On this page
    Represents an open connection to Google BigQuery.
    Syntax
    Remarks

    A BigQueryConnection object represents a unique connection to Google BigQuery. Use it in conjunction with BigQueryCommand, BigQueryDataReader, BigQueryDataAdapter or other components for convenient interoperation with Google BigQuery.

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

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

    Note that BigQueryConnection instance is not guaranteed to be thread safe. You should avoid using the same BigQueryConnection 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 BigQueryConnection can be used by many BigQueryCommand 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 BigQueryCommand and a BigQueryConnection. The BigQueryConnection 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 bigQueryConnectionString)
    {
      // If the connection string is empty, use default.
      if(bigQueryConnectionString == "")
      {
        bigQueryConnectionString = 
            @"Authentication Type=ServiceAccount;ServiceAccount Json=C:\keys\service-account.json;Project Id=your_project;DataSet Id=your_dataset;License Key=**********";
      }
      BigQueryConnection myConn = new BigQueryConnection(bigQueryConnectionString);
      string myInsertQuery = "INSERT INTO your_project.your_dataset.employees (first_name, last_name) VALUES ('John', 'Smith')";
      BigQueryCommand bigQueryCommand = new BigQueryCommand(myInsertQuery);
      bigQueryCommand.Connection = myConn;
      myConn.Open();
      try
      {
        bigQueryCommand.ExecuteNonQuery();
      }
      finally
      {
        myConn.Close();
      }
    }
    Public Sub InsertRow(bigQueryConnectionString As String)
      ' If the connection string is empty, use default.
      If bigQueryConnectionString = "" Then
        bigQueryConnectionString = _
            "Authentication Type=ServiceAccount;ServiceAccount Json=C:\keys\service-account.json;Project Id=your_project;DataSet Id=your_dataset;License Key=**********"
      End If
      Dim myConn As New BigQueryConnection(bigQueryConnectionString)
      Dim myInsertQuery As String = "INSERT INTO your_project.your_dataset.employees (first_name, last_name) VALUES ('John', 'Smith')"
      Dim bigQueryCommand As New BigQueryCommand(myInsertQuery)
      bigQueryCommand.Connection = myConn
      myConn.Open()
      Try
        bigQueryCommand.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.BigQuery.BigQueryConnection

    See Also