Get SQL statement in a catch(SqlException)

  • Thread starter Thread starter martijndemunnik
  • Start date Start date
M

martijndemunnik

I'm debugging an application using log4net. When a SQL statement fails
it is logged. One of the messages is

Line 1: Incorrect syntax near ')'.

but I'm not sure which SQL command is executed. Can I get the complete
SQL command send to the database server from an SqlException?
 
Hi,

No, I don't think you can. However, nothing prevents you to log each command
text before executing it.
 
Well I'm using a dataset with a dataadapter. I call the
dataadapter.update method and I can't tell wich sql commands are
executed. Is there a way to find out which SQL statements are executed
when I call the update methode?

thanks,

Martijn
 
just get SqlDataAdapter.UpdateCommand, could you please precise your
probleme and paste your code here?
 
The problem is that a paramater doesn't seem to be parsed in some
circumstances and I can't figure out which paramater and why. I would
like to see the parsed SQL statement sent to the server when an
sqlexception is thrown.
 
Then log all three commands (update, insert and delete).
If they are not too complicated it should be obvious why they fail by
looking at them.
 
Back
Top