I have been doing classing ASP and pretty new to ASP.NET. In classic ASP, I am normally response.write all the submitted values, make sure I am able to capture correct values, put those values in the SQL String, then response.write the SQL string before insert to SQL Server.
This helps to troubleshoot when there is an “SqlException” error, I just need copy/paste the whole query string in Server Management Studio and run it.
I wonder if there is any option in ASP.NET in which can perform sililiar like classic ASP. In ASP.Net, it display some errors, but it doesn’t show the value that I am submitting. For example, “[SqlException (0x80131904): Incorrect syntax near ‘]'”, I know where the problem in the query after review in the codes, but I would like to write whole the query string (with values submitted) in the screen so I can copy/pasted it in SQL Server Management Studio to troubleshoot it easier.
Debuging the errors/problems is very important for newbie like me. If there is no option like I described above in ASP.Net, please advise other alternative options if you know one.
Thanks in advance.
In the Microsoft IDEs (Visual Studio at least) you can click in the left margin (next to the line numbers if you have them turned on) and set breakpoints. You can test your code by hitting the green arrow (start debigging) or hitting I think it’s F5.
When you hit a breakpoint while debugging, the code stops executing and you can mouse over variables (like your SQL Statement) and make sure it’s what you’re expecting.
You could also turn on tracing in your page using Trace=”True” in the @Page directive, and use Trace.Warn to render your variable in the trace data. (This gives you a ton of other data in addition to what you’re looking for)