Setting up a Connection to ODBC in Delphi Using Devart ODBC Driver

Setting up a Connection to ODBC in Delphi Using Devart ODBC Driver

This guide will walk you through the steps of setting up a connection to an ODBC driver in Delphi. We'll use ODBC Driver for Salesforce as an example.

Prerequisites:

  1. Devart ODBC Driver for Salesforce installed on your machine.
  2. A Salesforce account for connection.
  3. Delphi IDE (Integrated Development Environment) for project development.

Step 1: Download and Install the ODBC Driver for Salesforce

Step 2: Configure the ODBC Driver for Salesforce

You can refer to detailed configuration instructions here.

After configuring the DSN, you can click on the Test Connection button to ensure the settings are correct.

Step 3: Create a New Delphi Project

Open Delphi IDE:
  1. Launch the Delphi IDE to create a new project.
Add Components:
  1. Create a small Delphi application that includes the necessary components:
A screenshot of a computer

AI-generated content may be incorrect., Зображення

Step 4: Configure the TUniConnection for ODBC

Use the following code to configure the TUniConnection component to connect via ODBC:
  1. uses ODBCUniProvider; 
  2. ... 
  3.   UniConnection.ProviderName := 'ODBC'; 
  4.   UniConnection.Server := 'Devart Salesforce Driver'; 
In this case, the Server property is set to the DSN you created in Step 2, specifically "Devart Salesforce Driver".

Alternatively, you can use the ConnectString property to define the ODBC connection without explicitly using the DSN. Here’s how you can configure it for Salesforce:
  1. UniConnection.ConnectString := 'Provider Name=ODBC;Server="DRIVER={Devart ODBC Driver for Salesforce};Data Source=login.salesforce.com;User ID=;Password=;Security Token="'; 

Step 5: Write the SQL Queries

  1. AccountQuery.SQL.Text := 'Select Id, Name, BillingStreet, BillingState, WebSite From Account'; 
  2. OpportunityQuery.SQL.Text := 'Select Name, StageName, Amount, Type, Description From Opportunity Where AccountId = :Id'; 
Info
Note that in both queries we did not use all the fields of the Account and Opportunity objects, but only those, which are needed for the demonstration. In addition, to implement the master-detail connection, we added the appropriate Where clause.

Step 6: Configure Master-Detail Relationship

Set Up Master-Detail Relationship:
  1. AccountDataSource.DataSet := AccountQuery; 
  2. OpportunityDataSource.DataSet := OpportunityQuery; 
  3. OpportunityQuery.MasterSource := AccountDataSource; 

Step 7: Open the Queries to Fetch Data

Execute the Queries:
  1.  AccountQuery.Open; 
  2.  OpportunityQuery.Open; 

Step 8: Review the Result

Below is a sample screenshot showing the result of the connection:
A screenshot of a computer

AI-generated content may be incorrect., Зображення
For the source code of this demonstration, you can download it from the following link: https://blog.devart.com/wp-content/uploads/2017/02/UniDACODBCDemo.zip
    • Related Articles

    • Setting up a Connection to Power BI Online Using Devart ODBC Driver

      In this guide, we will walk you through the process of setting up a connection to Power BI Online using the Devart ODBC Driver. This involves creating a DSN connection, setting up an on-premises gateway, and verifying Power BI report settings. Step ...
    • Setting up a Connection to QuickBooks Desktop Using Devart ODBC Driver

      This knowledge base article provides step-by-step instructions on how to set up a connection to QuickBooks Desktop using the Devart ODBC Driver. Following these steps will help you successfully connect to QuickBooks Desktop and retrieve your ...
    • Setting Up MongoDB Atlas and Connecting via Devart ODBC Driver

      This article will guide you through the process of setting up MongoDB Atlas, creating a cluster, configuring access, obtaining the connection string, and connecting to MongoDB Atlas using the Devart ODBC Driver for MongoDB. 1. Creating a Cluster in ...
    • How to Configure Devart ODBC Drivers for Optimal Performance

      To ensure optimal performance when using Devart ODBC drivers, it's recommended to fine-tune several key parameters: Connection Timeout — Set an appropriate timeout to avoid long waits on unresponsive connections. Data Fetching Size — Adjust the ...
    • Guide: Configuring ODBC Driver in Azure Data Factory

      This guide walks you through the steps of setting up and using an ODBC driver in Azure Data Factory (ADF) for seamless data integration. By following this guide, you will be able to configure an ODBC driver, create a Linked Service, and define an ...