我创建了一个方法,该方法会将抛出的任何异常插入 MySql 服务器上的“ExceptionLog”表中。
异常日志表格式
idExceptionLog int (AI) 用户 (varchar 45) ErrorMessage (varchart 4000)
问题是我不断收到以下错误。有谁知道为什么?
SqlParameterCollection 只接受非空的 SqlParameter 类型对象,不接受 MySqlParameter 对象。
private void showErrorBox(String errorMsg, MessageBoxButtons btnokshow)
{
MessageBox.Show(errorMsg, "FS Manager Error", MessageBoxButtons.OK);
// write to DB
string username = System.Environment.UserName.ToString();
string timestamp = DateTime.Now.ToString();
// Locals
SqlConnection NasDB = null;
SqlCommand inputError = null;
int rows = 0;
string spName = "ExceptionInsert";
try
{
//Instantiate the DB connection setting the conn string
using (NasDB = new SqlConnection(getConnectionString(ConnectionType.NAS)))
{
// Instantiate the command object that will fire the SP.
using (inputError = new SqlCommand(spName, NasDB))
{
// Finish setting up the command object
inputError.CommandType = CommandType.StoredProcedure;
// Set up the SP params.
inputError.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("ExceptionDate", MySql.Data.MySqlClient.MySqlDbType.DateTime, (1)));
inputError.Parameters[0].Value = timestamp;
inputError.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("User", MySql.Data.MySqlClient.MySqlDbType.VarChar, (45)));
inputError.Parameters[1].Value = System.Environment.UserName.ToString();
inputError.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("ExceptionMessage", MySql.Data.MySqlClient.MySqlDbType.VarChar, (4000)));
inputError.Parameters[2].Value = errorMsg;
// Now that the SP is completely set up and ready to go open the conn and fire the SP.
inputError.Connection.Open();
rows = inputError.ExecuteNonQuery();
// Close ASAP
inputError.Connection.Close();
}
}
}
catch (Exception ex)
{
//showErrorBox(ex.ToString());
throw ex;
}