This tutorial describes how to connect to Salesforce Marketing Cloud.
To connect to Salesforce Marketing Cloud, you need to have the corresponding account, dotConnect for Salesforce Marketing Cloud installed, and the IDE running. You also have to know the required connection parameters described below.
Note that if you do not use design-time (specifically, if you do not place designer ExactTargetConnection component from the Toolbox to the form), you have to embed licensing information manually. For more information, see Licensing.
To establish a connection to the server, you have to provide the required connection parameters to dotConnect for Salesforce Marketing Cloud. This information is used by ExactTargetConnection component to connect to Salesforce Marketing Cloud. The parameters are represented as a connection string. You can compose the connection string manually or have dotConnect for Salesforce Marketing Cloud construct it for you.
The following connection string parameters are required:
Salesforce Marketing Cloud supports four kinds of authentication - username/password, app center client (deprecated), server to server, and OAuth (RefreshToken). By default, username/password authentication is used. If you want to use this authentication, you need to set the Host, User Id, and Password parameters.
For OAuth (RefreshToken) authentication, set the Authentication Type parameter to AuthenticationType.RefreshToken and specify values for Client Id, Client Secret, Refresh Token, and Subdomain parameters.
For ServerToServer authentication, set the Authentication Type parameter to AuthenticationType.ServerToServer and specify values for Client Id, Client Secret, Refresh Token, and Subdomain parameters.
For app center client authentication, you need to set the Authentication Type parameter to AuthenticationType.AppCenterClient and specify values for Client Id and Client Secret parameters.
Note that AppCenterClient authentication is deprecated, and it is supported only for legacy packages. Since August 1, 2019, Marketing Cloud has removed the ability to create legacy packages, so any new packages are enhanced packages, not legacy packages, and they cannot use the App Center Client authentication. You can use this authentication only if you have a legacy package, created before August 1, 2019. For new packages, you need to use the RefreshToken authentication and provide the Refresh Token and Subdomain in addition to Client Id and Client Secret parameters.
Design time creation
The following assumes that you have the IDE running, and you are currently focused on a form designer.
Run time creation
You can also configure a connection at run-time by setting its ConnectionString property (note that you have to add references to Devart.Data.ExactTarget.dll, Devart.Data.SqlShim.dll, and Devart.Data.dll assemblies):
Using connection string builder
If you decide to set up the connection by assigning values to several properties, consider using ExactTargetConnectionStringBuilder class. It has all of the possible connection settings exposed as properties, thus allowing you to customize the connection to the full extent.
Notice that in this example we used the ExactTargetConnection constructor that accepts a connection string as an argument.
For information on the arguments allowed in the connection string, refer to the description of the ExactTargetConnection.ConnectionString property.
Creating Connection in Server Explorer
To create a Server Explorer connection:
After this, you can browse Salesforce Marketing Cloud objects in Server Explorer.
To open a connection, call the Open method.
The myConnection1 object must have a valid connection string assigned earlier. When you call Open, dotConnect for Salesforce Marketing Cloud tries to find the host and connect to Salesforce Marketing Cloud. If any problem occurs, it raises an exception with a brief explanation of what is wrong. If no problem is encountered, dotConnect for Salesforce Marketing Cloud tries to establish the connection during the ConnectionTimeout interval. Finally, when the connection is established, the Open method returns and the State property is changed to Open.
To connect to the server at design time:
Alternatively, change the State property to Open in the Properties window to establish a connection using the current connection string.
To close a connection, call its Close method, or set its State property to Closed.
The following example summarizes the aforementioned information and shows how to create, set up, open, use, and then close the connection.
The sample code connects to the server, shows its version, and then closes the connection. This is actually a rare usage, because in real applications connections are used by other objects like ExactTargetCommand, ExactTargetDataReader and others. For more information on this, see the corresponding tutorials or reference information.
You can modify a connection by changing properties of the ExactTargetConnection object. Keep in mind that while some of the properties can be altered freely, most of them close the connection when a new value is assigned.