Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MSCSqlException msx = new MSCSqlException(sqlQuery, sqlParams, sqlException);
- throw new Exception(ex.Message);
- MSCSqlException msx = new MSCSqlException(sqlQuery, sqlParams, sqlException);
- throw new Exception(ex.Message, ex);
- throw new MSCSqlException(sqlQuery, sqlParams, sqlException);
- [Serializable]
- public class MSCSqlException : Exception
- {
- public string SqlCommand { get; private set; }
- public object[] SqlParameters { get; private set; }
- public MSCSqlException()
- {
- }
- public MSCSqlException(string message)
- : base(message)
- {
- }
- public MSCSqlException(string message, Exception inner) : base(message, inner)
- {
- }
- public MSCSqlException(string command, object[] parameters, SqlException sx) : base(CreateUsefulMessage(sx, command, parameters), sx)
- {
- SqlCommand = command;
- SqlParameters = parameters;
- }
- protected MSCSqlException(SerializationInfo info, StreamingContext context) : base(info, context)
- {
- SqlCommand = info.GetString("SqlCommand");
- }
- [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- {
- throw new ArgumentNullException("info");
- }
- info.AddValue("SqlCommand", SqlCommand);
- base.GetObjectData(info, context);
- }
- public static string CreateUsefulMessage(SqlException sx, string sqlCommand, object[] sqlParameters)
- {
- string message = sx.Message + Environment.NewLine;
- if(sqlParameters != null && sqlParameters.Count() > 0)
- {
- message = message + "Parameters:" + Environment.NewLine;
- foreach(object sp in sqlParameters)
- {
- message = message + "t" + sp.ToString() + Environment.NewLine;
- }
- }
- message = message + "SQL Statement:" + Environment.NewLine;
- message = message + sqlCommand;
- return message;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement