build SQL text from SqlCommand

  • Thread starter Thread starter Giedrius
  • Start date Start date
G

Giedrius

Hi,
is it possible to retrieve exact sql text which will be executed from a
prepared SqlCommand or DBCommand?
I need this for logging all activity.

Something like this would be helpfull:

Command.CommandText = "ExecProc"
Command.Paramaters.Add.....

SQL = Command.GetInternalSql 'or Command.GetType.InvokeMember
("GetInternalSql")
 
Giedrius said:
Hi,
is it possible to retrieve exact sql text which will be executed from a
prepared SqlCommand or DBCommand?
I need this for logging all activity.

Something like this would be helpfull:

Command.CommandText = "ExecProc"
Command.Paramaters.Add.....

SQL = Command.GetInternalSql 'or Command.GetType.InvokeMember
("GetInternalSql")

You need to dump the CommandText, CommandType, and for each parameter the
ParameterName, Direction Type and Value.

This is what's sent to the server. It's not all munged up into a dynamic
SQL string.

David
 
Thanks,
thats how I do it now, but I thought about exact SQL string, without having
to think about command type, parameter types, parameter value formatting and
so on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top