SqlExceptionのロギングと同時に、最初にエラーが発生した場所のコンテンツを格納している別のDBを呼び出そうとしています。しかし、私はSqlConnectionの部分に「Unreachable code detected」という警告が表示されています。実行しようとしているプロシージャは実行されていません。C#例外例外句で別のDBのSQLプロシージャを呼び出す
catch (SqlException ex)
{
throw new DataException(ex.Message, ex);
//Call Error Management DB Connection and add content to the table
using (SqlConnection connection = new SqlConnection(_errorManagementConnectionString))
{
SqlCommand cmd = new SqlCommand("[dbo].[InsertDataErrors]", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@InputParam", InputParam);
cmd.Parameters.AddWithValue("@Content", Content);
cmd.ExecuteNonQuery();
connection.Open();
}
}
どのように私は、このエラーに取り組み、SQLExceptionが、私が実行しようとしている手順と一緒にログに記録されていることを確認することができますか?
あなたは 'using'部分の前に' new DataException'を投げていますので、使用できません。 – MatSnow
別の方法で試してみましたが、あらかじめ使用しておくと、新しいDataExceptionがスローされません。 – Dev
また、['AddWithValue'](https://stackoverflow.com/questions)の代わりに[' Add'](https://stackoverflow.com/questions/21110001/sqlcommand-parameters-add-vs-addwithvalue)を使用してください。/21110001/sqlcommand-parameters-add-vs-addwithvalue)。 – MatSnow