dotConnect for Dynamics 365 Documentation
Devart.Data.Dynamics Namespace / DynamicsConnection Class
Members Example

In This Topic
    DynamicsConnection Class
    In This Topic
    Represents an open connection to Dynamics CRM.
    Syntax
    Remarks

    A DynamicsConnection object represents a unique connection to Dynamics CRM. Use it in conjunction with DynamicsCommand, DynamicsDataReader, DynamicsDataAdapter or other components for convenient interoperation with Dynamics CRM.

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

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

    Note that DynamicsConnection instance is not guaranteed to be thread safe. You should avoid using the same DynamicsConnection 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 DynamicsConnection can be used by many DynamicsCommand 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 DynamicsCommand and a DynamicsConnection. The DynamicsConnection 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 dynamicsConnectionString)
    {
      // If the connection string is empty, use default.
      if(dynamicsConnectionString == "")
      {
        dynamicsConnectionString = 
            "Server=https://your_company.crm4.dynamics.com;User [email protected];Password=A123456789;";
      }
      DynamicsConnection myConn = new DynamicsConnection(dynamicsConnectionString);
      string myInsertQuery = "INSERT INTO Contact (FirstName,LastName) VALUES ('John','Smith')";
      DynamicsCommand dynamicsCommand = new DynamicsCommand(myInsertQuery);
      dynamicsCommand.Connection = myConn;
      myConn.Open();
      try
      {
        dynamicsCommand.ExecuteNonQuery();
      }
      finally
      {
        myConn.Close();
      }
    }
    Public Sub InsertRow(dynamicsConnectionString As String)
      ' If the connection string is empty, use default.
      If dynamicsConnectionString = "" Then
        dynamicsConnectionString = _
            "Server=https://your_company.crm4.dynamics.com;User [email protected];Password=A123456789;"
      End If
      Dim myConn As New DynamicsConnection(dynamicsConnectionString)
      Dim myInsertQuery As String = "INSERT INTO Contact (FirstName,LastName) VALUES ('John','Smith')"
      Dim dynamicsCommand As New DynamicsCommand(myInsertQuery)
      dynamicsCommand.Connection = myConn
      myConn.Open()
      Try
        dynamicsCommand.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.Dynamics.DynamicsConnection

    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