Click here to Skip to main content
15,885,757 members
Home / Discussions / C#
   

C#

 
QuestionHow can i know from which interface the method is calling? Pin
Satish - Developer27-Mar-10 2:46
Satish - Developer27-Mar-10 2:46 
AnswerRe: How can i know from which interface the method is calling? Pin
Nuri Ismail27-Mar-10 3:03
Nuri Ismail27-Mar-10 3:03 
AnswerRe: How can i know from which interface the method is calling? Pin
AspDotNetDev27-Mar-10 3:13
protectorAspDotNetDev27-Mar-10 3:13 
QuestionHow to write the design editor? Pin
yu-jian27-Mar-10 1:34
yu-jian27-Mar-10 1:34 
AnswerRe: How to write the design editor? Pin
yu-jian28-Mar-10 3:34
yu-jian28-Mar-10 3:34 
GeneralRe: How to write the design editor? Pin
OriginalGriff28-Mar-10 4:10
mveOriginalGriff28-Mar-10 4:10 
QuestionA question on SqlCommand.CommandText Pin
Dewald26-Mar-10 23:01
Dewald26-Mar-10 23:01 
AnswerRe: A question on SqlCommand.CommandText [modified] Pin
Dan Mos27-Mar-10 0:24
Dan Mos27-Mar-10 0:24 
Hy,

I've done something quite similar, exept I wrapped it in a Class.
It has some overloads:

Utils.Logs.Write(string message);
Utils.Logs.Write(string message, Exception ex);
Utils.Logs.Write(string message, SqlCommand cmd);
Utils.Logs.Write(string message, Exception ex, SqlCommand cmd);
Utils.Logs.Write(Exception ex, SqlCommand cmd);
Utils.Logs.Write(SqlCommand cmd);
Utils.Logs.Write(Exception ex);



[Edit]Actually it doesn't take a SQLCommand, nor a OleDbCommand as a param, but
a DBCommand wich can be found in System.Data.Common. Both SqlCommand and OleDbCommand

inherit from DbCommand so in order to avoid many oveloades for each type
of Command I used the DbCommand. In my original post I made a mistake and typed
SqlCommand in the params list for the Logs.Write() method. I'll live it like that.

Here's the code without the try...catch...finally for the DbCommand:

public static void Write(System.Data.Common.DbCommand cmd)
{           
            StreamWriter sw = GetLogFile();
            sw.WriteLine("SqlCommand: " + cmd.CommandText);
            if ((cmd.Parameters == null) || (cmd.Parameters.Count == 0))
            {
                sw.WriteLine("Parameters: No Params supplied;");
                sw.Flush();
                sw.Close();
            }
            else
            {
                sw.WriteLine("Parameters:");
                foreach (DbParameter pr in cmd.Parameters)
                {
                    sw.WriteLine(String.Format("ParamName: {0} => Value: {1}",
                        pr.ParameterName, pr.Value.ToString());
                }
                sw.Flush();
                sw.Close();
            }
}


[/Edit]

And the method takes the Message, InnerException(if any), StackTrace from the Excpetion,
and the CommandText and Params values from the Command object.

And here's a possible ouput for the overload that takes all three params using Jet Engine for example:
***************START*****************
Date: 27.03.2010::12:30

DeveloperMessage: Error executing the 'procGetStations' query.

SqlCommand: 
CommandText: "EXEC procGetStations";
Parameters: No Params supplied;


Exception: The Microsoft Jet database engine cannot find the input table or query 'procGetStations'.  Make sure it exists and that its name is spelled correctly.
Sourse: Microsoft JET Database Engine
InnerException: None available
StackTrace:    at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.OleDb.OleDbCommand.ExecuteReader()
   at DummyTest.StoredProcedures.StationProcedures.GetStations() in C:\DummyTest\StoredProcedures\Station.cs:line 27
***************END******************

modified on Saturday, March 27, 2010 7:16 AM

AnswerRe: A question on SqlCommand.CommandText Pin
#realJSOP27-Mar-10 1:29
mve#realJSOP27-Mar-10 1:29 
AnswerRe: A question on SqlCommand.CommandText Pin
PIEBALDconsult27-Mar-10 4:28
mvePIEBALDconsult27-Mar-10 4:28 
QuestionCompress a Folder using GZipStream Pin
anishkannan26-Mar-10 21:57
anishkannan26-Mar-10 21:57 
AnswerRe: Compress a Folder using GZipStream Pin
Richard MacCutchan26-Mar-10 23:05
mveRichard MacCutchan26-Mar-10 23:05 
GeneralRe: Compress a Folder using GZipStream Pin
AspDotNetDev26-Mar-10 23:23
protectorAspDotNetDev26-Mar-10 23:23 
GeneralRe: Compress a Folder using GZipStream Pin
Richard MacCutchan26-Mar-10 23:44
mveRichard MacCutchan26-Mar-10 23:44 
GeneralRe: Compress a Folder using GZipStream Pin
AspDotNetDev26-Mar-10 23:53
protectorAspDotNetDev26-Mar-10 23:53 
GeneralRe: Compress a Folder using GZipStream Pin
Richard MacCutchan27-Mar-10 3:19
mveRichard MacCutchan27-Mar-10 3:19 
GeneralRe: Compress a Folder using GZipStream Pin
AspDotNetDev27-Mar-10 3:27
protectorAspDotNetDev27-Mar-10 3:27 
GeneralRe: Compress a Folder using GZipStream Pin
Richard MacCutchan27-Mar-10 3:46
mveRichard MacCutchan27-Mar-10 3:46 
QuestionCompress a Folder Pin
anishkannan26-Mar-10 21:56
anishkannan26-Mar-10 21:56 
AnswerRe: Compress a Folder Pin
R. Giskard Reventlov26-Mar-10 22:00
R. Giskard Reventlov26-Mar-10 22:00 
AnswerRe: Compress a Folder Pin
Nuri Ismail26-Mar-10 22:19
Nuri Ismail26-Mar-10 22:19 
AnswerRe: Compress a Folder Pin
harold aptroot26-Mar-10 22:21
harold aptroot26-Mar-10 22:21 
AnswerRe: Compress a Folder Pin
AspDotNetDev26-Mar-10 23:17
protectorAspDotNetDev26-Mar-10 23:17 
AnswerRe: Compress a Folder Pin
AspDotNetDev26-Mar-10 23:21
protectorAspDotNetDev26-Mar-10 23:21 
Questionhow to convert our cheak box button act as a radio button Pin
poonam jagdale26-Mar-10 21:22
poonam jagdale26-Mar-10 21:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.