dotConnect for SugarCRM Documentation
On this page
    Connecting to SugarCRM
    On this page

    This tutorial describes how to connect to SugarCRM.

    Requirements

    To connect to SugarCRM, you need to have the corresponding account, dotConnect for SugarCRM 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 SugarConnection component from the Toolbox to the form), you have to embed licensing information manually. For more information, see Licensing.

    Required Connection Parameters

    To establish a connection to the server, you have to provide the required connection parameters to dotConnect for SugarCRM. This information is used by SugarConnection component to connect to SugarCRM. The parameters are represented as a connection string. You can compose the connection string manually or have dotConnect for SugarCRM construct it for you.

    The following connection string parameters are required:

    Creating a Connection to SugarCRM

    Design time creation

    The following assumes that you have the IDE running, and you are currently focused on a form designer.

    1. Open Toolbox and find SugarConnection component in the dotConnect for SugarCRM category.
    2. Double-click the component. Notice that a new object appears on the designer underneath the form. If this is the first time you create the SugarConnection in this application it is named sugarConnection1.
    3. Click the sugarConnection1 object and press F4 to focus on the object's properties.
    4. Enter the required connection string parameters, described above, to the corresponding boxes.
    5. Notice that as you assign values to these properties the ConnectionString property is automatically updated to reflect your settings. Now it contains something like "server=https://your_company.sugaropencloud.eu;user id=admin;password=AmFFA4ZryM;".
    6. If necessary, click the Advanced button and configure other connection string parameters. You can find the description of these connection string parameters in the SugarConnection.ConnectionString topic.

    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.Sugar.dll, Devart.Data.SqlShim.dll, and Devart.Data.dll assemblies):

    sugarConnection1.ConnectionString = "server=https://your_company.sugaropencloud.eu;user id=admin;password=AmFFA4ZryM;";
    
    sugarConnection1.ConnectionString = "server=https://your_company.sugaropencloud.eu;user id=admin;password=AmFFA4ZryM;"
    

    Using connection string builder

    If you decide to set up the connection by assigning values to several properties, consider using SugarConnectionStringBuilder class. It has all of the possible connection settings exposed as properties, thus allowing you to customize the connection to the full extent.

    SugarConnectionStringBuilder connectionStringBuilder = new SugarConnectionStringBuilder();
    
    connectionStringBuilder.Server = "https://your_company.sugaropencloud.eu";
    connectionStringBuilder.UserId = "admin";
    connectionStringBuilder.Password = "AmFFA4ZryM";
    
    SugarConnection myConnection = new SugarConnection(connectionStringBuilder.ConnectionString);
    
    Dim connectionStringBuilder As SugarConnectionStringBuilder = New SugarConnectionStringBuilder
    
    connectionStringBuilder.Server = "https://your_company.sugaropencloud.eu"
    connectionStringBuilder.UserId = "admin"
    connectionStringBuilder.Password = "AmFFA4ZryM"
    
    Dim myConnection As SugarConnection = New SugarConnection(connectionStringBuilder.ConnectionString)

    Notice that in this example we used the SugarConnection 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 SugarConnection.ConnectionString property.

    Creating Connection in Server Explorer

    To create a Server Explorer connection:

    1. On the Server Explorer toolbar, click Connect to Database.
    2. Under Data source, select SugarCRM Data Source.
    3. Under Data provider, select dotConnect for SugarCRM, then click Continue.
    4. Specify the Host (URL to connect to), User Id, and Password.
    5. Click OK.
    SugarCRM connection editor

    After this, you can browse SugarCRM objects in Server Explorer.

    SugarCRM connection in Server Explorer

    Opening a Connection

    To open a connection, call the Open method.

    myConnection1.Open();
    
    myConnection1.Open()
    

    The myConnection1 object must have a valid connection string assigned earlier. When you call Open, dotConnect for SugarCRM tries to find the host and connect to SugarCRM. If any problem occurs, it raises an exception with a brief explanation of what is wrong. If no problem is encountered, dotConnect for SugarCRM 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:

    1. Right-click the connection object in designer and select Connect.
    2. In the dialog window, enter the required connection parameters.
    3. Click the connection object and press F4 to focus on object's properties.
    4. If necessary, click Advanced and configure other connection string parameters. You can find the description of these connection string parameters in the SugarConnection.ConnectionString topic.
    5. Click Connect.

    Alternatively, change the State property to Open in the Properties window to establish a connection using the current connection string.

    Closing a Connection

    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.

    SugarConnection myConn = new SugarConnection();
    myConn.ConnectionString = "server=https://your_company.sugaropencloud.eu;user id=admin;password=AmFFA4ZryM;";
    myConn.Open();
    MessageBox.Show(myConn.ServerVersion);
    myConn.Close();
    
    Dim myConn As SugarConnection = New SugarConnection()
    myConn.ConnectionString = "server=https://your_company.sugaropencloud.eu;user id=admin;password=AmFFA4ZryM;"
    myConn.Open()
    MessageBox.Show(myConn.ServerVersion)
    myConn.Close()
    

    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 SugarCommand, SugarDataReader and others. For more information on this, see the corresponding tutorials or reference information.

    Modifying a Connection

    You can modify a connection by changing properties of the SugarConnection 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.