I'm trying to log an error message to a database when an exception is thrown. The idea is to have the exception be logged into the database so it can be investigated at a later time.
This is the code:
private void btnGroundMVC_Click(object sender, RoutedEventArgs e)
{
try
{
Process.Start(Library.paiplib.GroundMVC);
}
catch (Exception ex)
{
SqlConnection sqlconn = new SqlConnection(connectionString);
String timeStamp = Library.staticlib.getTimestamp(DateTime.Now);
SqlCommand cmd = new SqlCommand(errorlog, sqlconn);
cmd.Parameters.AddWithValue("@timeStamp", timeStamp);
cmd.Parameters.AddWithValue("@ex", ex);
sqlconn.Open();
cmd.ExecuteNonQuery();
sqlconn.Close();
MessageBox.Show(Library.paiplib.error + ex,"Error Loading PAIP", MessageBoxButton.OK,MessageBoxImage.Error);
}
This is the error message while debugging:
"An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
Additional information: No mapping exists from object type System.ArgumentException to a known managed provider native type."
This says that is at the cmd.ExecuteNonQuery();