0

When Connection is open this Exception occur

Code is:--

 SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = connection;
                connection.Open();
                Helper helper = new Helper(cmd);
helper.BeginTransaction();
Ayush
  • 1
  • 1
  • Hello! Have you read this? https://stackoverflow.com/questions/4074585/attempted-to-read-or-write-protected-memory-this-is-often-an-indication-that-ot It seems like your problem can be a lot of things. – Mr.Turtle Sep 27 '18 at 05:32
  • 1
    Possible duplicate of [System.AccessViolationException with SQLite](https://stackoverflow.com/questions/26951201/system-accessviolationexception-with-sqlite) – mjwills Sep 27 '18 at 05:58
  • @Ayush SQLite does not allow parallel writes. Just write from a single thread. (With databases, the bottleneck is likely to be the I/O anyway.) Can you write the code without the "Helper" class (which seems to be an multi-threaded-class)? – Mr.Turtle Sep 27 '18 at 06:22
  • Helper helper = new Helper(cmd); helper.BeginTransaction(); Both two line replace with method try { cmd.CommandText = "begin transaction;"; cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.Message); } It gives Exception of : **Database is not open ** When i open connection in a thread – Ayush Sep 27 '18 at 07:14
  • @Mr.Turtle :please help – Ayush Sep 27 '18 at 07:31
  • Are you getting any errors when you are calling "connetion.Open()"? It seems like you have a problem with your connection. Can you post the entire error stacktrace? – Mr.Turtle Sep 27 '18 at 10:06

0 Answers0