dotConnect for Salesforce Documentation
SalesforceConnection Class
Members  Example  See Also  Send comments on this topic.
Devart.Data.Salesforce Namespace : SalesforceConnection Class

Represents an open connection to Salesforce.com or Database.com.

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Data.Common.DbConnection
            Devart.Common.DbConnectionBase
               Devart.Data.Salesforce.SalesforceConnection

Syntax

Visual Basic (Declaration) 
Public Class SalesforceConnection 
   Inherits Devart.Common.DbConnectionBase
   Implements IComponentIDbConnectionICloneableIDisposable 
C# 
public class SalesforceConnection : Devart.Common.DbConnectionBase, IComponentIDbConnectionICloneableIDisposable  

Remarks

A SalesforceConnection object represents a unique connection to Salesforce.com or Database.com. Use it in conjunction with SalesforceCommand, SalesforceDataReader, SalesforceDataAdapter or other components for convenient interoperation with Salesforce.com or Database.com.

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

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

Note that SalesforceConnection instance is not guaranteed to be thread safe. You should avoid using the same SalesforceConnection 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 SalesforceConnection can be used by many SalesforceCommand 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 SalesforceCommand and a SalesforceConnection. The SalesforceConnection 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.
C#csharpCopy Code
public void InsertRow(string salesforceConnectionString) 
{ 
        // If the connection string is empty, use default. 
        if(salesforceConnectionString == "") 
        { 
                salesforceConnectionString = "Server=login.salesforce.com;User Id=name@company.com;
                   Password=mypassword;Security Token=qweASDzcx1234567890rtyui;"; 
        } 
        SalesforceConnection myConn = new SalesforceConnection(salesforceConnectionString); 
        string myInsertQuery = "INSERT INTO Account(Name) Values('New account')"; 
        SalesforceCommand salesforceCommand = new SalesforceCommand(myInsertQuery); 
        salesforceCommand.Connection = myConn; 
        myConn.Open(); 
        try 
        { 
                salesforceCommand.ExecuteNonQuery(); 
        } 
        finally 
        { 
                myConn.Close(); 
        } 
}
C#Visual BasicCopy Code
public void InsertRow(string salesforceConnectionString) 
{ 
        // If the connection string is empty, use default. 
        if(salesforceConnectionString == "") 
        { 
        salesforceConnectionString = "Server=login.salesforce.com;User Id=name@company.com;" & _
            "Password=mypassword;Security Token=qweASDzcx1234567890rtyui;"; 
        } 
SalesforceConnection myConn = new SalesforceConnection(salesforceConnectionString); 
string myInsertQuery = "INSERT INTO Account(Name) Values('New account')"; 
SalesforceCommand salesforceCommand = new SalesforceCommand(myInsertQuery); 
salesforceCommand.Connection = myConn; 
        myConn.Open(); 
        try 
        { 
                salesforceCommand.ExecuteNonQuery(); 
        } 
        finally 
        { 
                myConn.Close(); 
        } 
}

Requirements

Namespace: Devart.Data.Salesforce

Platforms:Windows Server 2003 R2, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8, Windows 10, Windows Server 2012 family.

See Also