dotConnect for FreshBooks Documentation
Devart.Data.FreshBooks Namespace / FreshBooksConnection Class
Members Example

FreshBooksConnection Class
Represents an open connection to FreshBooks.
Syntax
Remarks

A FreshBooksConnection object represents a unique connection to FreshBooks. Use it in conjunction with FreshBooksCommand, FreshBooksDataReader, FreshBooksDataAdapter or other components for convenient interoperation with FreshBooks.

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

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

Note that FreshBooksConnection instance is not guaranteed to be thread safe. You should avoid using the same FreshBooksConnection 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 FreshBooksConnection can be used by many FreshBooksCommand 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 FreshBooksCommand and a FreshBooksConnection. The FreshBooksConnection 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 freshbooksConnectionString)
{
  // If the connection string is empty, use default.
  if(freshbooksConnectionString == "")
  {
    freshbooksConnectionString = 
        "API Version=Alpha;Access Token=3d3355b2beea67f9241400fbe28f0b116e3efd2f8a85dda3c35620acdc95cd60;Refresh Token=75836f50da63fc5bf81bb24598511ae131ea422e73d9f321b4c4a44e2dd1c67f;Company Name=Devart";
  }
  FreshBooksConnection myConn = new FreshBooksConnection(freshbooksConnectionString);
  string myInsertQuery = "INSERT INTO Client (Email, FirstName, LastName) VALUES ('smithj@test1.com', 'John', 'Smith')";
  FreshBooksCommand freshbooksCommand = new FreshBooksCommand(myInsertQuery);
  freshbooksCommand.Connection = myConn;
  myConn.Open();
  try
  {
    freshbooksCommand.ExecuteNonQuery();
  }
  finally
  {
    myConn.Close();
  }
}
Public Sub InsertRow(freshbooksConnectionString As String)
  ' If the connection string is empty, use default.
  If freshbooksConnectionString = "" Then
    freshbooksConnectionString = _
        "API Version=Alpha;Access Token=3d3355b2beea67f9241400fbe28f0b116e3efd2f8a85dda3c35620acdc95cd60;Refresh Token=75836f50da63fc5bf81bb24598511ae131ea422e73d9f321b4c4a44e2dd1c67f;Company Name=Devart"
  End If
  Dim myConn As New FreshBooksConnection(freshbooksConnectionString)
  Dim myInsertQuery As String = "INSERT INTO Client (Email, FirstName, LastName) VALUES ('smithj@test1.com', 'John', 'Smith')"
  Dim freshbooksCommand As New FreshBooksCommand(myInsertQuery)
  freshbooksCommand.Connection = myConn
  myConn.Open()
  Try
    freshbooksCommand.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.FreshBooks.FreshBooksConnection

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also