Getting Started With dotConnect for SugarCRM

Below are some resources to help you maximize your experience with dotConnect for SugarCRM.

dotConnect for SugarCRM is a high-performance ADO.NET data provider with ORM support, offering fast and encrypted access to SugarCRM data for application development.

  • EF Core, Dapper, NHibernate ORM support
  • Local SQL engine with support for SQL-92
  • Broad compatibility with various .NET platforms and versions
  • Full compliance with ADO.NET
  • Integration with Visual Studio

Code examples

using Devart.Data.Sugar;

namespace SugarConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string host = "https://test.sugaropencloud.com";
            string userId = "test";
            string password = "test";
            string licenseKey = "**********";

            string connectionString = $"Host={host};User Id={userId};Password={password};License Key={licenseKey}";

            try
            {
                CheckConnectionStatus(connectionString);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred: " + ex.Message);
            }
        }

        public static void CheckConnectionStatus(string myConnString)
        {
            using (SugarConnection sugarConnection = new SugarConnection(myConnString))
            {
                try
                {
                    sugarConnection.Open();
                    Console.WriteLine("Connection successful.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Connection failed: " + ex.Message);
                }
            }
        }
    }
}
PM> Install-Package Devart.Data.Sugar
using Devart.Data.Sugar;

namespace SugarConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string host = "https://test.sugaropencloud.com";
            string userId = "test";
            string password = "test";
            string licenseKey = "**********";

            string connectionString = $"Host={host};User Id={userId};Password={password};License Key={licenseKey}";

            try
            {
                ReadContactsData(connectionString);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred: " + ex.Message);
            }
        }

        public static void ReadContactsData(string myConnString)
        {
            using (SugarConnection sugarConnection = new SugarConnection(myConnString))
            {
                try
                {
                    sugarConnection.Open();
                    Console.WriteLine("Connection successful.");
                    Console.WriteLine(); // Break line
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Connection failed: " + ex.Message);
                    Console.WriteLine(); // Break line
                    return;
                }

                using (SugarCommand sugarCommand = (SugarCommand)sugarConnection.CreateCommand())
                {
                    sugarCommand.CommandText = "SELECT Id, Name FROM Contacts";

                    using (SugarDataReader sugarReader = sugarCommand.ExecuteReader())
                    {
                        try
                        {
                            // Always call Read before accessing data.
                            int rowCount = 0;
                            while (sugarReader.Read() && rowCount < 15)
                            {
                                Console.WriteLine($"Id: {sugarReader["Id"]}");
                                Console.WriteLine($"Name: {sugarReader["Name"]}");
                                Console.WriteLine(); // Break line
                                rowCount++;
                            }
                        }
                        finally
                        {
                            // Always call Close when done reading.
                            sugarReader.Close();
                        }
                    }
                }
            }
        }
    }
}
PM> Install-Package Devart.Data.Sugar
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using SugarEFCore;

// Build configuration
var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
    .Build();

// Get connection string
var connectionString = configuration.GetConnectionString("sugarModelConnectionString");

// Configure DbContext
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseSugar(connectionString);

// Create DbContext instance
using (var db = new sugarModel(optionsBuilder.Options))
{
    Console.WriteLine("Contacts Table:");

    // Print header
    Console.WriteLine("{0,-25} | {1,-15} | {2,-20} | {3,-30}", "Name", "Work Phone", "City", "Email");
    Console.WriteLine(new string('-', 90));

    // Query and display contacts
    var contacts = db.Contacts.Take(10).ToList();
    foreach (var contact in contacts)
    {
        var fullName = $"{contact.FirstName} {contact.LastName}";
        Console.WriteLine("{0,-25} | {1,-15} | {2,-20} | {3,-30}", 
            fullName, 
            contact.PhoneWork, 
            contact.PrimaryAddressCity, 
            contact.Email1);
    }
}
PM> Install-Package Devart.Data.Sugar.EFCore
using System.Data;
using Devart.Data.Sugar;

namespace SugarConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string host = "https://test.sugaropencloud.com";
            string userId = "test";
            string password = "test";
            string licenseKey = "**********";

            string connectionString = $"Host={host};User Id={userId};Password={password};License Key={licenseKey}";

            try
            {
                FetchContactsWithDataAdapter(connectionString);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred: " + ex.Message);
            }
        }

        public static void FetchContactsWithDataAdapter(string myConnString)
        {
            using (SugarConnection sugarConnection = new SugarConnection(myConnString))
            {
                try
                {
                    sugarConnection.Open();
                    Console.WriteLine("Connection successful.");
                    Console.WriteLine();

                    // Create a SugarDataAdapter instance
                    SugarDataAdapter sugarDataAdapter = new SugarDataAdapter("SELECT Id, Name FROM Contacts", sugarConnection);

                    // Create a DataSet to hold the results
                    DataSet dataSet = new DataSet();

                    // Fill the DataSet with data from the adapter
                    sugarDataAdapter.Fill(dataSet);

                    // Access the data from the DataSet
                    if (dataSet.Tables.Count > 0)
                    {
                        DataTable contactsTable = dataSet.Tables[0];
                        int rowCount = 0;

                        foreach (DataRow row in contactsTable.Rows)
                        {
                            if (rowCount >= 15)
                                break;

                            Console.WriteLine($"Id: {row["Id"]}");
                            Console.WriteLine($"Name: {row["Name"]}");
                            Console.WriteLine();
                            rowCount++;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Connection failed: " + ex.Message);
                }
            }
        }
    }
}
PM> Install-Package Devart.Data.Sugar

How-to articles

.NET Connection String for SugarCRM
Learn how to set up connection strings properly when working with dotConnect for SugarCRM in .NET applications.
Connect to SugarCRM in .NET
Explore how to establish a connection between .NET applications and SugarCRM using ADO.NET.
Connect to SugarCRM with EF Core
Find out how to connect SugarCRM to your application using EF Core and ADO.NET.

Documentation

Licensing
Licensing
A detailed technical reference on embedding license information - a required resource for applications built with dotConnect for SugarCRM.
DataAdapter features
DataAdapter features
A guide to using the SugarCRMDataAdapter class for interacting with SugarCRM data in a disconnected architecture.
Parameters
Parameters
An overview of SQL query parameters and their synchronization, along with practical insights into working with stored procedures.
SQL translation
SQL translation
An introduction to using translatable SQL for query performance optimization through remote execution instead of client-side processing.

dotConnect Universal

Get universal access to data from a variety of sources, including SQL Server, Oracle, PostgreSQL, MySQL, SQLite, DB2, InterBase, Microsoft Access, and Firebird. Other servers can be accessed through their ADO.NET, OLE DB and ODBC providers.

FAQ

What is the trial period for dotConnect for SugarCRM?
dotConnect for SugarCRM offers a fully functional 30-day trial. During this period, you can use and evaluate all features without limitations. After the trial ends, you can purchase a license to keep using the product.
Why do I need to install the product if NuGet is available?

dotConnect for SugarCRM provides two sets of assemblies, and the choice depends on your project type:

  • For .NET (.NET Core/.NET 5+) projects: Use the assemblies available via NuGet packages.
  • For .NET Framework projects: Use the Devart assemblies included with the product installer.
Where should I apply my License Key?

Add the License Key parameter to your connection string together with other connection parameters. For more information, see Licensing.

Do end-users of my application require a Devart license, or must I pay additional fees for deploying my software?

No, end users do not need a Devart license, and there are no additional deployment fees, as long as you hold a valid Devart license.

According to the EULA, you're allowed to redistribute the following runtime assemblies with your application:

  • Devart.Data.Sugar.dll
  • Devart.Data.dll

You can include them in your app's folder (such as Bin for web apps) or register them in the GAC. Just make sure they are only used by your solution.

There's no need for a full installation on the target machine, you can also use the "Minimal installation" option provided by the setup.

No other components of dotConnect may be distributed.

How can I update dotConnect to a new version?

To update dotConnect to a new version, you need to reinstall it:

  1. Open Settings > Apps > Installed apps in Windows.
  2. Uninstall the current and any older versions of dotConnect, including Entity Developer and LinqConnect, if installed.
  3. Visit the Customer Portal and download the latest licensed version.
  4. Install the downloaded version and receive the latest features and improvements.
How can I completely remove all previous versions of a product?
  1. Go to Settings > Apps > Installed apps and uninstall:
    • All dotConnect providers
    • Entity Developer
    • LinqConnect
  2. Manually delete any leftover files from the following locations (if they exist):

    GAC folders:

    • C:\Windows\assembly\GAC_MSIL
    • C:\Windows\Microsoft.NET\assembly\GAC_MSIL

    Program files and extensions:

    • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\Devart
    • C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Devart
    • C:\Program Files (x86)\Devart
    • C:\Program Files\Devart
    • C:\Program Files (x86)\Common Files\Devart
    • C:\Program Files\Common Files\Devart

    Program data folders:

    • C:\ProgramData\Devart\dotConnect
    • C:\ProgramData\Devart\Entity Developer

Removing these ensures a clean system and prevents conflicts during future installations.

dotConnect for SugarCRM

Get an enhanced ORM-enabled data provider for SugarCRM and develop .NET applications with SugarCRM data quickly and easily!

Discover the ultimate capabilities of dotConnect for SugarCRM Download free trial