CommandAsSql/ExtensionMethods.cs
/// <summary>
/// This method fills all parameters of the sqlcommand and displays it as a string which can be copy pasted in your DB management tool for debug purposes.
/// </summary>
/// <param name="command">The SqlCommand you want parsed as a full SQL string</param>
/// <returns></returns>
This method fills all parameters of the sqlcommand and displays it as a string which can be copy pasted in your DB management tool for debug purposes.
This method fills all parameters of the sqlcommand and displays it as a string which can be copy pasted in your DB management tool for debug purposes .
public static string CommandAsSql(this SqlCommand command)
        {
            var sql = new System.Text.StringBuilder();
            if (command.Connection != null)
                sql.Append("use ").Append(command.Connection.Database).AppendLine(";");
            foreach (SqlParameter strucParam in command.Parameters.GetStructured())
                sql.AppendLine(strucParam.ParameterValueForSQL());
            switch (command.CommandType)
            {
                case CommandType.Text: 
                    command.CommandAsSql_Text(sql);
                    break;
                case CommandType.StoredProcedure:
                    command.CommandAsSql_StoredProcedure(sql);
                    break;
            }
            return sql.ToString();
        }
public static string CommandAsSql ( this SqlCommand command ) { var sql = new System . Text . StringBuilder ( ) ; if ( command . Connection != null ) sql . Append ( " " ) . Append ( command . Connection . Database ) . AppendLine ( " " ) ; foreach ( SqlParameter strucParam in command . Parameters . GetStructured ( ) ) sql . AppendLine ( strucParam . ParameterValueForSQL ( ) ) ; switch ( command . CommandType ) { case CommandType . Text : command . CommandAsSql_Text ( sql ) ; break ; case CommandType . StoredProcedure : command . CommandAsSql_StoredProcedure ( sql ) ; break ; } return sql . ToString ( ) ; }
This method fills all parameters of the sqlcommand and displays it as a string which can be copy pasted in your DB management tool for debug purposes.
This method fills all parameters of the sqlcommand and displays it as a string which can be copy pasted in your DB management tool for debug purposes .
//checking 1st, since if we use Text SQL Commands we'll probably be logging more of them that if we had them grouped in Stored Procedures
None
SqlCommand
this
<not_specific>
command
<not_specific>
The SqlCommand you want parsed as a full SQL string
The SqlCommand you want parsed as a full SQL string