Skip to content

Allow configuring SQLite synchronous mode in the connection string #38769

Description

@JamesNK

What problem are you trying to solve?

PRAGMA synchronous is scoped to a native SQLite connection and is not persisted in the database. Applications that require a specific mode, such as NORMAL for a WAL database, must execute the PRAGMA for every physical connection.

Microsoft.Data.Sqlite pooling makes this awkward. After SqliteConnection.Open(), an application cannot tell whether Microsoft.Data.Sqlite created a new native connection or leased an already-configured one from the pool. The reliable application-level workaround is therefore to execute the PRAGMA after every logical open:

var connection = new SqliteConnection(connectionString);
connection.Open();

using var command = connection.CreateCommand();
command.CommandText = "PRAGMA synchronous = NORMAL;";
command.ExecuteNonQuery();

This adds boilerplate and an extra command to every open. It is also easy for one connection-opening path to omit the configuration.

The connection string already supports analogous connection-scoped configuration such as Foreign Keys=True. Microsoft.Data.Sqlite reapplies that setting when a connection is opened, including when a physical connection is obtained from the pool.

This request is narrower than #5024, which was redirected to general EF lifecycle interception, and #13826, which addressed preserving configuration when reopening the same SqliteConnection. Neither provides a connection-string option that consistently configures all physical connections in a Microsoft.Data.Sqlite pool.

Observed with Microsoft.Data.Sqlite.Core 10.0.10.

Describe the solution you'd like

Add a Synchronous connection-string keyword and corresponding strongly typed SqliteConnectionStringBuilder.Synchronous property, for example:

var connectionString = new SqliteConnectionStringBuilder
{
    DataSource = databasePath,
    ForeignKeys = true,
    Synchronous = SqliteSynchronousMode.Normal
}.ToString();

The supported values could map to SQLite's modes:

  • Off / 0
  • Normal / 1
  • Full / 2
  • Extra / 3

When specified, Microsoft.Data.Sqlite would apply PRAGMA synchronous after obtaining the native connection during Open(), similar to the existing Foreign Keys behavior. When omitted, the provider would preserve SQLite's default behavior.

Including the value in the connection string would also naturally partition pools whose connections require different synchronous modes.

Activity

  1. added theissue type on Aug 8, 2026
  2. AhmedSadek10 commented on Aug 13, 2026

    @AhmedSadek10
    Contributor

    I’d like to work on this issue. My plan is to add a Synchronous option to SqliteConnectionStringBuilder, introduce a SqliteSynchronousMode enum for Off/Normal/Full/Extra, apply the corresponding PRAGMA synchronous when the connection is opened, and add builder and connection-level tests. Is this approach acceptable?

    @JamesNK

  3. AndriySvyryd commented on Aug 14, 2026

    @AndriySvyryd
    Member

    @AhmedSadek10 Sounds good, make sure it's only called once when reopening a pooled connection.

    This feature is related to #29186

  4. added this to the Backlog milestone on Aug 14, 2026
  5. modified the milestones: Backlog, 12.0.0 on Sep 10, 2026
  6. added a commit that references this issue on Sep 10, 2026
    fd0f112
  7. added a commit that references this issue on Sep 25, 2026
    aad793c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions