Results 1 to 5 of 5

Thread: Pragma wal/wal2

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2021
    Posts
    4

    Question Pragma wal/wal2

    I'm using VS 2019 16.9.4 and I'm writing a database program using SQLite. I'm not sure how concurrent writing and reading to and from database is handled by default. I have read the SQLite WAL modes notes, but I still don't quite understand.

    By default is journaling enabled?

    Is this how you enable WAL2?

    Public connectionString As String = String.Format("Data Source = {0}; PRAGMA journal_mode=WAL2", dtBasePath)

    Thanks for the help.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jun 2021
    Posts
    4

    Re: Pragma wal/wal2

    Quote Originally Posted by vkohli View Post
    I'm using VS 2019 16.9.4 and I'm writing a database program using SQLite. I'm not sure how concurrent writing and reading to and from database is handled by default. I have read the SQLite WAL modes notes, but I still don't quite understand.

    By default is journaling enabled?

    Is this how you enable WAL2?

    Public connectionString As String = String.Format("Data Source = {0}; PRAGMA journal_mode=WAL2", dtBasePath)

    Thanks for the help.

    I figured it out. Assume your database name is dBase.

    Remove PRAGMA from the connectionString. So it should read:

    ..("Data Source = {0}; journal_mode=WAL2", ...)

    It will create both a dBase-wal and dBase-shm.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Pragma wal/wal2

    OT: every ADO.NET provider has a class dedicated to building connection strings. If you're using SQLite then your provider will have a SqliteConnectionStringBuilder class and I would recommend using it. It's a neater and less error-prone way to build provider-specific connection strings in code.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2021
    Posts
    4

    Re: Pragma wal/wal2

    Quote Originally Posted by jmcilhinney View Post
    OT: every ADO.NET provider has a class dedicated to building connection strings. If you're using SQLite then your provider will have a SqliteConnectionStringBuilder class and I would recommend using it. It's a neater and less error-prone way to build provider-specific connection strings in code.
    Thanks for the suggestion. I'll take a look at string builder. I did notice that once the journal mode of the database is set to WAL/WAL2 it is persistent. So it only needs to be set once. To roll back you will have to set the journal mode to DELETE.

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Pragma wal/wal2

    OT2:
    regarding the Pragma: IIRC, you can fire off a PRAGMA against SQLite (after connection is established) like an SQL-Statement
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width