Skip to content

Pragma Settings for SQLite #5024

Closed as duplicate
Closed as duplicate

Description

@shlatchz

The following code

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    var connectionStringBuilder = new SqliteConnectionStringBuilder() { DataSource = Constants.DataDBPath  };
    var connectionString = connectionStringBuilder.ToString();
    var connection = new SQLiteConnection() { ConnectionString = connectionString };
    optionsBuilder.UseSqlite(connection);
}

cannot receive pragma settings such as journalmode or syncmode.
How can I apply the pragma settings to the db?

I tried:

using (var context = new DataDBContext())
{
    var connection = context.Database.GetDbConnection();
    connection.Open();
    var command = connection.CreateCommand();
    command.CommandText = "PRAGMA synchronous=OFF; PRAGMA journal_mode=OFF; PRAGMA count_changes=OFF; PRAGMA temp_store=OFF; PRAGMA page_size=65536; PRAGMA cache_size=-16777216;";
    command.ExecuteNonQuery();
}

but it didn't help.

Activity

  1. ErikEJ commented on Apr 10, 2016

    @ErikEJ
    Contributor

    You need to do it in the same context as where you are doing the EF data access

  2. shlatchz commented on Apr 10, 2016

    @shlatchz
    Author

    Can you please elaborate?
    Are you saying that I have to do it each time I modify the DB?

  3. rowanmiller commented on Apr 15, 2016

    @rowanmiller
    Contributor

    @natemcmaster can you confirm?

  4. added this to the 1.0.0 milestone on Apr 19, 2016
  5. rowanmiller commented on May 11, 2016

    @rowanmiller
    Contributor

    @natemcmaster ping 😄

  6. modified the milestones: 1.0.1, 1.0.0 on May 11, 2016
  7. natemcmaster commented on May 11, 2016

    @natemcmaster
    Contributor

    @shlatchz if you want to issue custom pragma statements, you need to do this every time you open a connection. Changing values via pragma statements do not persist across calls to sqlite_open_v2. At the moment, we don't have API in Microsoft.Data.Sqlite.SqlConnection to support executing something arbitrary (such as issuing pragma statements) everytime a connection opens.

    Moving up a layer in the stack. EntityFramework Core has a class that wraps SqliteConnection. This wrapper handles opening/closing SqliteConnection and has its own logic for issuing pragma statements when connections open. See Microsoft.EntityFrameworkCore.Storage.Internal.SqliteRelationalConnection. EF lets you pass an connection object instead of a connection string if you want to manage the lifecycle of opening/closing a connection yourself. UseSqlite(DbConnection connection).

  8. removed this from the 1.0.1 milestone on May 11, 2016
  9. natemcmaster commented on May 11, 2016

    @natemcmaster
    Contributor

    Remarking for triage: what is the work here? Add API to Microsoft.Data.Sqlite or EF?

  10. 5 remaining items

  11. rowanmiller commented on Jul 6, 2016

    @rowanmiller
    Contributor

    BTW just to make it explicit - we are not closing this because we aren't planning to implement it. We very much agree this is super useful, it's just already tracked as part of #626.

  12. added a commit that references this issue on Mar 11, 2020
  13. added a commit that references this issue on Mar 30, 2020
  14. modified the milestones: , 1.1.0 on Oct 15, 2022
  15. removed this from the 1.1.0 milestone on Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions