How to connect C# to Salesforce via ADO.NET

Salesforce data is critical, but integrating it cleanly into C# applications is rarely straightforward. REST-based approaches often introduce fragmented authentication logic, brittle mappings, and operational overhead that grows with every new integration. 

That complexity is why many teams still rely on ADO.NET. This data access API remains the most practical workhorse for database-style access in C#, thanks to its connection–command–reader model and predictable behavior. 

In Salesforce integrations, this model is often implemented through dotConnect for Salesforce, giving .NET applications SQL-like access to Salesforce objects while keeping the surrounding application architecture unchanged. 

Why dotConnect for Salesforce 

dotConnect for Salesforce provides a complete ADO.NET provider for Salesforce, handling authentication, metadata mapping, and query translation internally. This lets .NET teams work with Salesforce data using familiar patterns, while avoiding custom API code and integration-specific plumbing. 

How to download and activate dotConnect for Salesforce 

30-day free trial version 

You can start using dotConnect for Salesforce immediately with a 30-day free trial. Choose one of the following installation options: 

  • NuGet: Add the Devart.Data.Salesforce package to your project. 

To activate a 30-day trial, use the license key assigned to you after completing the registration on the Devart website. 

Full version 

After you’ve purchased the full version, follow these steps: 

  1. Go to the Products section in your Devart profile. 
  2. Click the product name, or hover over it and click Details. The License details page opens, where you can find the Activation Key. 


3. To activate dotConnect for Salesforce in your application, copy the Activation Key and paste it into your connection string as the License Key parameter. 

Get the Salesforce security API token 

Salesforce enforces robust security measures for API access. When using username-password authentication, you need a security token to verify the connection if you’re logging in from a new IP address or device. To obtain the security token in Salesforce: 

  1. Log in to your Salesforce account. 
  2. Go to your profile and select Settings. 

3. Navigate to Reset My Security Token. 

4. Request a security token reset. 

5. Salesforce sends a new security token to the email address associated with your account. 

You’ll use this token together with your Salesforce password when configuring the connection string for API access. 

Install packages 

After installing and activating dotConnect for Salesforce, you need to add the required NuGet packages to your .NET project. These packages provide the assemblies used by your application at runtime. 

Follow these steps in Visual Studio: 

  1. Open Visual Studio and load your project. 
  2. In Solution Explorer, right-click the project and select Manage NuGet Packages. 
  3. Open the Browse tab. 
  4. Search for Devart.Data.Salesforce and click Install. 
  5. Search for Devart.Data.SqlShim and click Install. 

NuGet automatically selects the appropriate assemblies based on your project’s target framework. Once both packages are installed, your project is ready to use dotConnect for Salesforce in code. 

Project setup 

At this point, dotConnect for Salesforce is installed, activated, and added to your project. The next step is to verify everything works end to end by creating a simple Console App in Visual Studio. Any supported .NET target is fine. This is just a lightweight way to confirm that your connection and credentials are set up correctly. 

In the console application shown in the next section, you will: 

  • Build a Salesforce connection string. 
  • Open a connection using SalesforceConnection. 
  • Run a SQL-like query with SalesforceCommand. 
  • Read the results using SalesforceDataReader. 

dotConnect for Salesforce works with .NET Framework 4.5+ as well as modern .NET/.NET Core runtimes, so you can use the same approach in production applications later on. 

Connection setup 

With the project in place, you can now define the connection to Salesforce. The application uses Devart.Data.Salesforce and a standard connection string that contains everything required to authenticate and open a session. 

The connection string includes: 

  • Authentication Type — UserNamePassword. 
  • Host — login.salesforce.com for production or developer orgs, test.salesforce.com for sandboxes. 
  • User Id — your Salesforce username. 
  • Password — your Salesforce password. 
  • Security Token — the token emailed by Salesforce. 
  • License Key — your dotConnect for Salesforce license key. 

SQL query to fetch data 

With the connection in place, the next step is to define a query. dotConnect for Salesforce lets you use SQL-like syntax to retrieve data from Salesforce objects, which keeps querying familiar if you’re coming from a database background. 

For example, the following query selects a few commonly used fields from the Account object: 

At this point, nothing is executed yet—you’re simply defining what data you want to retrieve.

Command execution 

To run the query, create a SalesforceCommand and execute it against the open connection. Calling ExecuteReader() returns a SalesforceDataReader, which provides forward-only access to the result set. 

This pattern mirrors standard ADO.NET usage, so it should feel immediately familiar if you’ve worked with SQL Server, Oracle, or other data providers. 

Processing query results 

Once the reader is available, you can iterate through the results row by row. Each field is accessed by name, and null values can be handled safely to avoid runtime errors.

This pattern gives you predictable, forward-only access to Salesforce data and aligns cleanly with established ADO.NET workflows. 

Full example of code: Salesforce console .NET application 

To see everything working together, here’s a complete, minimal console application. It opens a connection to Salesforce, runs a query against the Account object, and prints the results to the console. 

Results 

Run the console application. If the host, credentials, security token, and license key are all correct, you should see: 

  • “Connected to Salesforce successfully.” 
  • A list of Account records with IdNamePhone, and Website, or a message indicating that no data was found. 

At this point, you’ve confirmed that your C# application can connect to Salesforce and query live data using ADO.NET-style patterns. 

Final word 

Connecting C# to Salesforce through ADO.NET provides a clear, production-ready way to integrate CRM data into .NET applications without rebuilding your data-access layer. With dotConnect for Salesforce, Salesforce objects are accessed through familiar ADO.NET patterns (connections, commands, and readers) while authentication, licensing, and environment targeting remain explicit and easy to manage. This makes it easier to move integrations confidently from development to sandbox and into production. 

Once basic querying is in place, teams typically focus on productivity and maintainability. dotConnect supports this progression by enabling higher-level approaches such as LINQ and ORM-based access, including Entity Framework options, when projects require richer mapping, change tracking, or more complex query composition across larger integration surfaces. 

Responses

Popular Salesforce Blogs