0

When I enter an incorrect database in the above code, the catch part catches the error but does not close the application. a simple error, but could not solve.

OleDbConnection conn;
string connectionString = "Provider=Microsoft.ACE.Oledb.12.0; Data Source=xx.accdb";
public void connect()
{
    conn = new OleDbConnection(connectionString);

    try
    {
        this.conn.Open();
    }
    catch(Exception)
    {
        MessageBox.Show("Error.");
        Aplication.Exit();
    }
}
DiplomacyNotWar
  • 31,605
  • 6
  • 57
  • 75
regex
  • 13
  • 1

2 Answers2

1

Use Environment.Exit(). check this related question for more info :

Application.Exit() not working

Also note that MessageBox.Show("Error.") will block the execution flow until you click OK.

Mohammad Ghanem
  • 619
  • 6
  • 19
0
 conn.Close(); //dont forget

Environment.Exit(0) //or use -> System.Environment.Exit(0);
StrTOInt
  • 16
  • 2