dotConnect for SugarCRM Documentation
Devart.Data.Sugar Namespace / SugarConnection Class
Members Example

In This Topic
    SugarConnection Class
    In This Topic
    Represents an open connection to SugarCRM.
    Syntax
    Remarks

    A SugarConnection object represents a unique connection to SugarCRM. Use it in conjunction with SugarCommand, SugarDataReader, SugarDataAdapter or other components for convenient interoperation with SugarCRM.

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

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

    Note that SugarConnection instance is not guaranteed to be thread safe. You should avoid using the same SugarConnection 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 SugarConnection can be used by many SugarCommand 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.

    This class supports cross-form data binding with the InterForm Technology.

    Example
    The following example creates a SugarCommand and a SugarConnection. The SugarConnection 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 sugarConnectionString)
    {
      // If the connection string is empty, use default.
      if(sugarConnectionString == "")
      {
        sugarConnectionString = 
            "server=https://your_company.sugaropencloud.eu;user id=admin;password=AmFFA4ZryM;";
      }
      SugarConnection myConn = new SugarConnection(sugarConnectionString);
      string myInsertQuery = "INSERT INTO Campaigns (name, campaign_type, end_date, status) VALUES ('Sale campaign', 'Email', '2016-12-12', 'Active')";
      SugarCommand sugarCommand = new SugarCommand(myInsertQuery);
      sugarCommand.Connection = myConn;
      myConn.Open();
      try
      {
        sugarCommand.ExecuteNonQuery();
      }
      finally
      {
        myConn.Close();
      }
    }
    Public Sub InsertRow(sugarConnectionString As String)
      ' If the connection string is empty, use default.
      If sugarConnectionString = "" Then
        sugarConnectionString = _
            "server=https://your_company.sugaropencloud.eu;user id=admin;password=AmFFA4ZryM;"
      End If
      Dim myConn As New SugarConnection(sugarConnectionString)
      Dim myInsertQuery As String = "INSERT INTO Campaigns (name, campaign_type, end_date, status) VALUES ('Sale campaign', 'Email', '2016-12-12', 'Active')"
      Dim sugarCommand As New SugarCommand(myInsertQuery)
      sugarCommand.Connection = myConn
      myConn.Open()
      Try
        sugarCommand.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.Sugar.SugarConnection

    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