How is possible to get actual commandText string from SqlCommand object ?
SqlCommand cmd = new Command();
cmd.CommandText = "wpr_A_O_OST";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@USERID","{8773A3BD-E661-4E95-8733-4182D910EF64}");
........
string cmdText = ???; // I need to get command string that is actually
sended to Sql Server.
Something like this " exec wpr_A_O_OST
@USERID='{8773A3BD-E661-4E95-8733-4182D910EF64}' "
There isn't anything in the System.Data.SqlClient namespace that will
allow you to access this directly.
What exactly are you trying to do?
--
- Nicholas Paldino [.NET MVP]
- nicholas...@exisconsulting.com
"Ivar" <lumi...@neti.ee> wrote in message
news:OTP1XSRnBHA.1156@tkmsftngp07...
I need log exact commandText sended to server.
Earlier i didn't use SqlCommand class i used
constructed string like this
" exec wpr_A_O_OST @USERID='{8773A3BD-E661-4E95-8733-4182D910EF64}' "
Then it was easy to log commands.
Excactly why i need it is, when SqlCommand fails i want my program to send
me commandText.
Later i can use commandText in Query Analyser track the error.
"Nicholas Paldino [.NET MVP]" <nicholas...@exisconsulting.com> wrote in
message news:eOr#ZeRnBHA.1944@tkmsftngp07...
If your SQL command fails, you can probably trap the exception and send
that to you (along with a detailed description of what caused the
exception).
The reason I suggest this is because more likely than not, it will be
something outside of the command that fails (due to a network error or
something like that).
However, if you want to get the exact text that was sent, you are going
to have to intercept it on some other level, possibly by monitoring socket
traffic. I don't know if you will be able to do this in .NET, though.
--
- Nicholas Paldino [.NET MVP]
- nicholas...@exisconsulting.com
"Ivar" <lumi...@neti.ee> wrote in message
news:#S8BeHSnBHA.1948@tkmsftngp03...
You could quite easily re-construct the text yourself though. You know it's
a stroed procedure, therefore you have "exec", (at least if you're using
MSSQL), you have the stored proc name, " wpr_A_O_OST", and you have the
parameters " @USERID...". I would say this is your easiest bet
Dean Bisseker
Pontefract, England
You can see that using the MSSQL Profiler
You could. I think Ivar want's his program to log the command before it is
sent to MSSQL. However, like Nicholas I suspect the actual command text sent
to the server is quite likely to not be causing a problem.
As always there are many ways to solve a problem, and most of them only
prove that the problem you thought you had actually isn't what's causing you
the grief.
Dean Bisseker
> , like Nicholas I suspect the actual command text sent
> to the server is quite likely to not be causing a problem.
In most times yes, but if paramter(s) is wrong value, SqlException always
doesn't
give you exact information.
Sometimes it give you line 0, error converting datatype. - which parameter
caused ???
If you have more than 20 params, this is real headache.
"Dean Bisseker" <de...@neosoft.co.uk> wrote in message
news:eo#uMqSnBHA.1688@tkmsftngp03...