Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

Unable to set foreign_keys pragma #324

Closed
ghost opened this issue Feb 12, 2017 · 1 comment
Closed

Unable to set foreign_keys pragma #324

ghost opened this issue Feb 12, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Feb 12, 2017

I don't know why, but it just won't work for me. Am I doing something wrong?

using (var conn = new Microsoft.Data.Sqlite.SqliteConnection("Filename=./Data/database.db"))
{
  conn.Open();
  using (var tr = conn.BeginTransaction())
    {
      var com = conn.CreateCommand();
      com.CommandText = "PRAGMA foreign_keys = 1";
      com.ExecuteNonQuery();

      var com2 = conn.CreateCommand();
      com2.CommandText = "PRAGMA foreign_keys";
      await ReplyAsync(com2.ExecuteScalar().ToString());

      tr.Commit();
    }
}

image

@ghost ghost closed this as completed Feb 13, 2017
@bricelam
Copy link
Contributor

Looks like you figured it out. For others: PRAGMA foreign_keys doesn't work inside a transaction.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant