Showing posts with label sqlcommand. Show all posts
Showing posts with label sqlcommand. Show all posts

Friday, February 24, 2012

Debugging Parameterized Queries

How would I debug such a query.

I have a sqlCommand to which I add several parameters for an insert statement.

if the statement fails, for some reason, I would like to copy the final sql with all values inserted as text and use this in e.g. TOAD to see where the error is coming from. Is this possible?

I have also been looking for this, but there does not seem to be a public property of the Command object that exposes this. I don't think it is actually stored in the object anywhere. I think it is created on the fly, when sent to the database.

What you can do however, if you don't have too many parameters, is to just copy/paste the SQL command into your TOAD. If you prefix your OracleParameters with : (instead of @.) then TOAD will ask you for the value of each parameter as you run your query.

Another option (although a bit cumbersome) is to write a function that actually parses the CommandText property and inserts the current values of the parameters, with respect to their datatype... But it would take some work to get it right ;-)

Friday, February 17, 2012

Debug SQL Server Stored Procedure

How can I debug a Stored Procedure called by an ASP.Net application using SqlCommand.ExecuteScalar function?

You can use SQL Profiler to open a trace to the SQL Server with adding Stored Procedure Events. You can start from here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_mon_perf_51df.asp