Guest User

Untitled

a guest
Dec 18th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. bool TryingtoStart = true;
  2.  
  3. while (TryingtoSTart)
  4. {
  5. try
  6. {
  7. dbc.Open();
  8.  
  9. departmentDataAdapter = new SQLiteDataAdapter("select * from DEPARTMENT", dbc);
  10. // etc
  11. }
  12.  
  13. catch (SQLiteException ex)
  14. {
  15. DialogResult r = MetroFramework.MetroMessageBox.Show(this, ex.Message.ToString(), "Database error", MessageBoxButtons.RetryCancel);
  16.  
  17. if (r == DialogResult.Cancel) TryingtoStart = false;
  18. }
  19.  
  20. catch (Exception exc)
  21. {
  22. DialogResult r = MetroFramework.MetroMessageBox.Show(this, exc.Message.ToString(), "Exception", MessageBoxButtons.RetryCancel);
  23. if (r == DialogResult.Cancel) TryingtoStart = false;
  24. }
  25.  
  26. if (!TryingtoStart) Application.Exit();
  27. }
  28.  
  29. "Operation is not valid due to the current state of the object."
  30.  
  31. System.InvalidOperationException: Operation is not valid due to the current state of the object.
  32. at System.Data.SQLite.SQLiteConnection.Open()
  33.  
  34. bool TryingtoStart = true;
  35.  
  36. while (TryingtoSTart)
  37. {
  38.  
  39. using(var dbc = new SQLiteConnection(connectionString))
  40. {
  41. try
  42. {
  43. using(var departmentDataAdapter = new SQLiteDataAdapter("select * from DEPARTMENT", dbc))
  44. {
  45. // etc
  46. }
  47.  
  48. // Note: This row will only be executed if there where no exceptions until this point in the code
  49. TryingtoStart = false;
  50. }
  51.  
  52. catch (SQLiteException ex)
  53. {
  54.  
  55. if (MetroFramework.MetroMessageBox.Show(this, ex.Message.ToString(), "Database error", MessageBoxButtons.RetryCancel) == DialogResult.Cancel) Application.Exit();
  56. }
  57. catch (Exception exc)
  58. {
  59. if (MetroFramework.MetroMessageBox.Show(this, exc.Message.ToString(), "Exception", MessageBoxButtons.RetryCancel) == DialogResult.Cancel) Application.Exit();
  60. }
  61. }
  62. }
Add Comment
Please, Sign In to add comment