0

This is kind of the most annoying thing I've ever worked with. As I understand, when opening a new Query Window, a new connection is created, but in SQLite query window (I'm using Visual Studio integrated Designer for SQLite), it seems to be created every time you click Execute (a red !) button. And the PRAGMA foreign_keys = ON seems to take effect only in a session of connection (means that, after connection is closed, it turns to 0/OFF). If I'm wrong please explain to me why this happens:

-> First, I right-click on the SQLite [My database] (right under the Data Connections node in Server Explorer window in Visual Studio 2010) -> select New Query -> start typing PRAGMA foreign_keys -> shows result: 0 -> try turning it on by PRAGMA foreign_keys = ON -> check if it is ON by PRAGMA foreign_keys -> Still shows result: 0 =>>>> What???

That means I can't turn it on, and I can't benefit from Foreign Key Constraint to keep my data integral.

If foreign_keys is some attribute of a database or a table, it should be always ON/1 once I have turned it on. Therefore, I think that 'liquid' stuff is some attribute of Connection. Can't work with it.

Please help... Thanks!

King King
  • 61,710
  • 16
  • 105
  • 130
  • 1
    What happens if you execute two commands together: `PRAGMA foreign_keys = ON; PRAGMA foreign_keys;`? – CL. Apr 06 '13 at 08:44
  • Of course, it shows 1, but as I said, all the commands which are executed in a single clicking on the red ! are in fact in the same session of connection and that's why it takes effect. But I intend to use Adapter and I'm not sure when the connection is opened and closed to insert the PRAGMA foreign_keys = ON at a proper position. Thanks! – King King Apr 06 '13 at 09:09
  • 1
    Why not set it in the connection string? http://stackoverflow.com/questions/4254371/enabling-foreign-key-constraints-in-sqlite – ta.speot.is Apr 06 '13 at 09:13
  • @ta.speot.is Wow you saved my life, I couldn't believe there was such a simple solution... Now it works perfectly as I want... WOWWWW, I love SQLite for local database projects in my life... Thanks so much!!! – King King Apr 06 '13 at 09:31

0 Answers0