I have a SqlCommand object on my c# based asp.net page. The SQL and the passed parameters are working the majority of the time. I have one case that is not working, I get the following error:
String or binary data would be truncated. The statement has been terminated.
I understand the error and but all the columns in the database should be long enough to hold everything being sent.
My questions,
Is there a way to see what the actual SQL being sent to the database is from SqlCommand object? I would like to be able to email the SQL when an error occurs.
Thanks, Justin
Whilst not perfect, here's something I knocked up something for TSQL - could be easily tweaked for other flavours... If nothing else it will give you a start point for your own improvements :)
This does an OK job on data types and output parameters etc similar to using "execute stored procedure" in SSMS. We mostly used SPs so the "text" command doesn't account for parameters etc
this generates output along these lines...
Check out this question it should provide what you are looking for.
Get the generated SQL statement from a SqlCommand object?
While you will not be able to plug is into something like Enterprise Manager to run it works for logging.
You need to use the SQL Server Profiler to watch what comes from the application. I believe it can show you the SQL and the parameters, which you will need to see.