3
Answers

OleDb Exception Handling

Ask a question
Hello. I am new to C# and have a question regarding catching specific exceptions. Below is my code and I would like to know if there is a better way. I would like the catch the specific OldeDbException for "invalid passsword" but how can I do this? What would I place in the Catch() statement? I used an if/then statement to catch it but is there another way in the catch block to specify an exact exception (invalid password)?

tx
  try
  { dbConn.Open();}
 catch (OleDbException e)
  {
   if (e.ErrorCode == -2147217843)
  {Console.WriteLine("Invalid Password Entered"); }
  else
  { Console.WriteLine(e.Message);}
  }

Answers (3)