.NET MAUI (Multi-platform App UI) is a framework developed by Microsoft for building native mobile and desktop applications using C# and .NET. It allows developers to create apps that run on Android, iOS, Windows, and macOS. One of its biggest advantages is the ability to use a single codebase letting the developers share code, tests, and program logic across multiple platforms.

A key aspect of app development is ensuring a reliable connection to data sources and direct data management within the application. Data connectivity solutions, such as Devart's dotConnect products, help us resolve these challenges efficiently.

In this article, we'll explore how to connect a .NET MAUI application to a Salesforce data source using ADO.NET and perform read, insert, and delete operations.

Why dotConnect for Salesforce?

Integration with Salesforce

Easy integration with Salesforce

Ensures effortless connection to Salesforce, enabling users to access data easily and intuitively.

Secure connection ensured

No Salesforce API and SOQL learning

Supports familiar SQL statements, requiring no special knowledge of a complex API or SOQL.

Support for ADO.NET classes

User-friendly ADO.NET classes

Uses well-known ADO.NET classes, enabling an easy start and creating a convenient working environment.

ORM support provided

Advanced ORM support

Fully supports EF Core, Dapper, NHibernate, LinqConnect, and other technologies for efficient data management.

Full ADO.NET compliance

Full ADO.NET compliance

Conforms to the latest ADO.NET standards and innovations for seamless integration with .NET applications.

Priority support provided

Priority support & frequent updates

Includes priority support, detailed documentation, and regular updates for continuous improvement.

Download and activate dotConnect for Salesforce

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

30-day free trial version

dotnet add package Devart.Data.Salesforce
Install-Package Devart.Data.Salesforce

You can install the driver by using the Windows installer.

After you receive the license key, add it to your connection strings to connect to the data source.

Start using dotConnect for Salesforce in your project today with a free trial

Get the security API token

To connect to Salesforce and access the data, you need the security token. Sign in to your Salesforce account, go to your profile > Settings. Navigate to Reset My Security Token and request it. A new token will be sent to your email. We'll use it for API access when we establish connection to Salesforce.

Reset the Salesforce Security API token

Create a connection

This article includes a sample of the code that you can use to connect to Salesforce using dotConnect within a .NET MAUI project.

Replace the placeholders with your valid Salesforce credentials: Host, UserID, Password, and Security Token.

Note
For a paid dotConnect for Salesforce license, include the license key in the code. For the trial version, remove the License Key line.
private readonly string _connectionString;

public SalesforceService() {
  _connectionString = "Authentication Type=UserNamePassword;" +
    "Host=https://develop.my.salesforce.com;" +
    "[email protected];" +
    "Password=******;" +
    "Security Token=***********;" +
    "License Key=***********;";
}

public async Task<bool> TestConnectionAsync() {
  try {
    using(var connection = new SalesforceConnection(_connectionString)) {
      connection.Open();
      return true;
    }
  } catch {
    return false;
  }
}

Connection strings

Name Description
Authentication type The authentication method for connecting to Salesforce, such as UserNamePassword, AccessRefreshToken, AccessRefreshTokenInteractive, SessionId, etc.
Host The Salesforce.com or Database.com login URL, such as login.salesforce.com, login.database.com, test.salesforce.com, etc.
User ID -or- User The Salesforce login account.
Password The password for the account.
Refresh token The Salesforce OAuth 2.0 refresh token used for the OAuth Refresh Token authentication.
Security token User ID used to authenticate with MySQL.
License key The license key.

We are going to use our demo SalesforceMaui project to illustrate the READ, INSERT, and DELETE operations.

Read Salesforce data

To read and display data from your Salesforce account in an MAUI app, use the code below in the SalesforceService.cs class. In this code, the following ADO.NET classes are used:

  • SalesforceConnection manages the connection lifecycle.
  • SalesforceCommand represents the SQL query.
  • SalesforceDataReader reads query results row by row.
public async Task<List<LeadModel>> GetLeadDataAsync() {
  var leadData = new List<LeadModel>();

  try {
    using(var connection = new SalesforceConnection(_connectionString)) {
      connection.Open();

      string query = "SELECT Id, FirstName, LastName, Company, Title, Phone, Email, Status FROM Lead LIMIT 15";
      using(var command = new SalesforceCommand(query, connection)) {
        using(var reader = command.ExecuteReader()) {
          while (reader.Read()) {
            leadData.Add(new LeadModel {
                Id = reader["Id"].ToString(),
                FullName = $"{reader["FirstName"]} {reader["LastName"]}",
                DetailInfo = $"Company: {reader["Company"]}, Title: {reader["Title"]}, Phone: {reader["Phone"]}, Email: {reader["Email"]}, Status: {reader["Status"]}"
            });
          }
        }
      }
    }
  } catch (Exception ex) {
    Console.WriteLine($"Error retrieving data: {ex.Message}");
  }

  return leadData;
}

The results are displayed in the table:

<Label Text="Leads Table" FontAttributes="Bold" Margin="0,10,0,5" />
<CollectionView x:Name="DataCollectionView" ItemsSource="{Binding LeadData}" VerticalOptions="FillAndExpand">
<CollectionView.ItemTemplate>
    <DataTemplate>
     <Grid Padding="5" ColumnDefinitions="*,*,Auto">
         <!-- Full Name -->
         <Label Grid.Column="0" Text="{Binding FullName}" FontSize="16" />

         <!-- Detail Info -->
         <Label Grid.Column="1" Text="{Binding DetailInfo}" FontSize="12" TextColor="Gray" />

         <!-- Delete Button -->
         <Button Grid.Column="2" Text="Delete" TextColor="White" BackgroundColor="Red"
            Command="{Binding Path=BindingContext.DeleteCommand, Source={x:Reference DataCollectionView}}"
            CommandParameter="{Binding Id}" />
        </Grid>
    </DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>

Read Salesforce data in a .NET MAUI project

Add data to Salesforce

To add data to Salesforce tables from within the MAUI app, use the code below with the ADO.NET classes:

  • SalesforceConnection manages connection lifecycle.
  • SalesforceCommand prepares and executes the INSERT query.
  • SalesforceParameter ensures secure and parameterized queries.
public async Task<bool>
AddLeadAsync(string firstName, string lastName, string company, string title, string phone, string email, string status) {
  try {
    using(var connection = new SalesforceConnection(_connectionString)) {
      connection.Open();

      string query = "INSERT INTO Lead (FirstName, LastName, Company, Title, Phone, Email, Status) VALUES (@FirstName, @LastName, @Company, @Title, @Phone, @Email, @Status)";
      using(var command = new SalesforceCommand(query, connection)) {
        command.Parameters.AddWithValue("FirstName", firstName ?? string.Empty);
        command.Parameters.AddWithValue("LastName", lastName ?? string.Empty);
        command.Parameters.AddWithValue("Company", company ?? string.Empty);
        command.Parameters.AddWithValue("Title", title ?? string.Empty);
        command.Parameters.AddWithValue("Phone", phone ?? string.Empty);
        command.Parameters.AddWithValue("Email", email ?? string.Empty);
        command.Parameters.AddWithValue("Status", status ?? string.Empty);

        command.ExecuteNonQuery();
      }
    }
    return true;
  } catch (Exception ex) {
    Console.WriteLine($"Error adding lead: {ex.Message}");
    return false;
  }
}

The table to display the results is:

<VerticalStackLayout Padding="10" Spacing="10">
	<Label Text="Add New Lead" FontAttributes="Bold" FontSize="20" HorizontalOptions="Center" />

	<Grid ColumnDefinitions="*,3*" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto" RowSpacing="15" Padding="0,10,0,10">
    	<!-- First Name -->
    	<Label Text="First Name:" VerticalTextAlignment="Center" />
    	<Entry x:Name="FirstNameEntry" Placeholder="First Name" Grid.Column="1" />

    	<!-- Last Name -->
    	<Label Text="Last Name:" VerticalTextAlignment="Center" Grid.Row="1" />
    	<Entry x:Name="LastNameEntry" Placeholder="Last Name" Grid.Row="1" Grid.Column="1" />

    	<!-- Company -->
    	<Label Text="Company:" VerticalTextAlignment="Center" Grid.Row="2" />
    	<Entry x:Name="CompanyEntry" Placeholder="Company" Grid.Row="2" Grid.Column="1" />

    	<!-- Title -->
    	<Label Text="Title:" VerticalTextAlignment="Center" Grid.Row="3" />
    	<Entry x:Name="TitleEntry" Placeholder="Title" Grid.Row="3" Grid.Column="1" />

    	<!-- Phone -->
    	<Label Text="Phone:" VerticalTextAlignment="Center" Grid.Row="4" />
    	<Entry x:Name="PhoneEntry" Placeholder="Phone" Grid.Row="4" Grid.Column="1" />

    	<!-- Email -->
    	<Label Text="Email:" VerticalTextAlignment="Center" Grid.Row="5" />
    	<Entry x:Name="EmailEntry" Placeholder="Email" Grid.Row="5" Grid.Column="1" />

    	<!-- Status -->
    	<Label Text="Status:" VerticalTextAlignment="Center" Grid.Row="6" />
    	<Entry x:Name="StatusEntry" Placeholder="Status" Grid.Row="6" Grid.Column="1" />
	</Grid>
</VerticalStackLayout>

<Button Text="Add Lead" Clicked="OnAddLeadClicked" />

Add new records to Salesforce from the .NET MAUI project

Delete Salesforce records

To delete records from the Salesforce tables, use the code below with the following ADO.NET classes:

  • SalesforceConnection manages the database connection lifecycle.
  • SalesforceCommand represents the SQL query and executes it.
  • SalesforceParameter binds parameters securely to the SQL query.
public async Task<bool> DeleteLeadAsync(string id) {
  try {
    using(var connection = new SalesforceConnection(_connectionString)) {
      connection.Open();

      string query = "DELETE FROM Lead WHERE Id = @Id";
      using(var command = new SalesforceCommand(query, connection)) {
        command.Parameters.AddWithValue("Id", id);

        command.ExecuteNonQuery();
      }
    }
    return true;
  } catch (Exception ex) {
    Console.WriteLine($"Error deleting lead: {ex.Message}");
    return false;
  }
}
}

The Delete button in the Leads table that we presented earlier in this article is created with the following code:

<Button Grid.Column="2" Text="Delete" TextColor="White" BackgroundColor="Red" Command="{Binding Path=BindingContext.DeleteCommand, Source={x:Reference DataCollectionView}}" CommandParameter="{Binding Id}" />

Conclusion

.NET MAUI is a popular framework for cross-platform application development. In this process it is crucial to ensure efficient connectivity to data sources. dotConnect products provide that required secure, direct connection and allow direct data manipulation from within the application.

If your MAUI app relies on Salesforce, dotConnect for Salesforce grants a stable connection and enables you to manage Salesforce tables without additional clients or learning new technologies.

You can test dotConnect for Salesforce under real workloads with a 30-day free trial. Download, install, and start building your applications!

FAQ

How do you install and activate dotConnect for Salesforce in a .NET project?
Install dotConnect for Salesforce via the EXE installer or by adding the Devart.Data.Salesforce NuGet package to your project, then obtain your personal activation key from your Devart Customer Portal and include it in the connection string via the License Key parameter for a working connection.
How do you create a connection to Salesforce using dotConnect in C#?
Define a connection string that includes host, user ID, password, database, and the License Key value, then create a SalesforceConnection instance with this string and call Open() for it inside a try-catch block to test and handle connection errors.
How do you enable encryption for secure Salesforce connections with dotConnect?
Use Salesforce Native Network Encryption by configuring encryption in the sqlnet.ora file on both client and server sides. No special parameters are required in the connection string.
Can you connect to Salesforce using Entity Framework Core and dotConnect?
Yes, you can either use Entity Developer to visually create an EF Core model from the database or run Scaffold-DbContext with a dotConnect connection string (including License Key) to generate the DbContext and entity classes.
Is it possible to connect to Salesforce using Visual Studio Server Explorer with dotConnect?
Yes, it is possible. All you need to do is navigate to Visual Studio Server Explorer, add a new Data Connection, choose dotConnect for Salesforce as the data provider, enter your credentials, test the connection, and then browse Salesforce data directly in Visual Studio.

Dereck Mushingairi

I'm a technical content writer who loves turning complex topics — think SQL, connectors, and backend chaos–into content that actually makes sense (and maybe even makes you smile). I write for devs, data folks, and curious minds who want less fluff and more clarity. When I'm not wrangling words, you'll find me dancing salsa, or hopping between cities.

Try the 30-day trial of the full product. No limits. No card required. Start free trial