How can I close my application when I got an error?

G

Guest

I have a window Application. this.close(); doesn't stop and close my
application when I get an error. Instead it continues trying to execute the
following codes. What code do I need to the application to exit where it
catches the exception and close down the application?

Thanks, Alpha

conDB = new SqlConnection(conStr);

try
{
conDB.Open();
scUpdate = conDB.CreateCommand();
conDB.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error connecting to the database server. VMS can't run
with out database connection and VMS will be closing down. " + ex.ToString()+
"Please contact your support person.", "VMS - Database Open Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();

}
 
G

Guest

It's asking for ExitCode, as System.Environment.Exit(ExitCode), when I
compile the program. What should I put in there? 0?
Thanks.
 
G

Guest

I tried the Application.Exit in place of this.Close() but I got the same
result. The application just continues with the codes and give more error
message.

Thanks, Alpha
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top