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();
    }
}
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
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
  • 688
  • 6
  • 20
0
 conn.Close(); //dont forget

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