dotConnect for Adobe Commerce Documentation
Devart.Data.Magento Namespace / MagentoConnection Class
Members Example

In This Topic
    MagentoConnection Class
    In This Topic
    Represents an open connection to Adobe Commerce.
    Syntax
    Remarks

    A MagentoConnection object represents a unique connection to Adobe Commerce. Use it in conjunction with MagentoCommand, MagentoDataReader, MagentoDataAdapter or other components for convenient interoperation with Adobe Commerce.

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

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

    Note that MagentoConnection instance is not guaranteed to be thread safe. You should avoid using the same MagentoConnection 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 MagentoConnection can be used by many MagentoCommand 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 MagentoCommand and a MagentoConnection. The MagentoConnection 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 adobe commerceConnectionString)
    {
      // If the connection string is empty, use default.
      if(adobe commerceConnectionString == "")
      {
        adobe commerceConnectionString = 
            "domain=192.168.10.68/magento;user=Test;apikey=testpassword;";
      }
      MagentoConnection myConn = new MagentoConnection(adobe commerceConnectionString);
      string myInsertQuery = "INSERT INTO Customers (email, firstname, lastname) VALUES ('[email protected]', 'John', 'Smith')";
      MagentoCommand adobe commerceCommand = new MagentoCommand(myInsertQuery);
      adobe commerceCommand.Connection = myConn;
      myConn.Open();
      try
      {
        adobe commerceCommand.ExecuteNonQuery();
      }
      finally
      {
        myConn.Close();
      }
    }
    Public Sub InsertRow(adobe commerceConnectionString As String)
      ' If the connection string is empty, use default.
      If adobe commerceConnectionString = "" Then
        adobe commerceConnectionString = _
            "domain=192.168.10.68/magento;user=Test;apikey=testpassword;"
      End If
      Dim myConn As New MagentoConnection(adobe commerceConnectionString)
      Dim myInsertQuery As String = "INSERT INTO Customers (email, firstname, lastname) VALUES ('[email protected]', 'John', 'Smith')"
      Dim adobe commerceCommand As New MagentoCommand(myInsertQuery)
      adobe commerceCommand.Connection = myConn
      myConn.Open()
      Try
        adobe commerceCommand.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.Magento.MagentoConnection

    See Also