Home All Groups Group Topic Archive Search About

Get SQL statement in a catch(SqlException)

Author
24 Apr 2006 11:42 AM
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?

Author
24 Apr 2006 11:48 AM
Miha Markic [MVP C#]
Hi,

No, I don't think you can. However, nothing prevents you to log each command
text before executing it.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

<martijndemun***@gmail.com> wrote in message
Show quote
news:1145878929.387871.241670@g10g2000cwb.googlegroups.com...
> 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?
>
Author
24 Apr 2006 1:18 PM
martijndemunnik
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
Author
24 Apr 2006 1:29 PM
zacqaria
just get SqlDataAdapter.UpdateCommand, could you please precise your
probleme and paste your code here?
Author
24 Apr 2006 2:07 PM
martijndemunnik
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.
Author
24 Apr 2006 3:04 PM
Miha Markic [MVP C#]
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.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

<martijndemun***@gmail.com> wrote in message
Show quote
news:1145884695.875315.110410@y43g2000cwc.googlegroups.com...
> 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
>
Author
24 Apr 2006 3:15 PM
Paul
If you're using MS SQL Server could you try SQL Profiler?

Show quote
"martijndemun***@gmail.com" wrote:

> 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
>
>

AddThis Social Bookmark Button