0

How do I debug a page in ASP.NET? I have an IIS server that I am trying to add a new page to and when I am running the ASP on the server I get a really short and nondescript error message

Microsoft OLE DB Provider for SQL Server error '80040e14' 
      Incorrect syntax near '='. 
/forms/test.asp, line 52

Line 52 is:

Set RS = Conn.Execute(SQL)

Where 'SQL' is a SQL query statement set a few lines earlier. I have checked that statement over and over I am confident that the syntax of the query is solid as a nearly identical query runs without a hitch earlier in the page and other pages run the same thing. I have been working for a while now to try to find the bug with no success.

I am new to ASP and working in an IIS environment. I usually work with Java in which I have a stack trace to gather information and can use console output to track data to help with the debugging process. This is all absent in ASP.

So, what methods can I use to track this bug and solve it? I know I list a specific example here but I really need a general technique I can use to debug ASP. Can I print to a console somewhere to track variable values? Can I send that information out in a popup so I can see what the data looks like before the error? Is there some way to get a more detailed description about what happens on execution so I can track where I am going wrong?

Thank you for your help!

EDIT

The SQL Statement is:

SQL = "SELECT firstname,lastname FROM clientinfo WHERE [ClientID] = " & Request("ID")

Even if we can solve this problem though, is there some technique to debug ASP easier?

Dead_Jester
  • 602
  • 6
  • 9
  • 18
  • 1
    It really does look like a sql error. Just before you call .Execute, `Response.Write(SQL) Response.End` and check the sql string. This is ASP classic, by the way - about 15 years old :) – StuartLC Apr 04 '14 at 14:06
  • I agree with StuartLC, show us the SQL statement that is executed, you probably miss some quotes around a string parameter. – kloarubeek Apr 04 '14 at 14:28
  • Added the Statement to the post, is there something wrong with it? – Dead_Jester Apr 04 '14 at 14:39
  • Are you sure it's `Request("ID")`? Are you sure it isn't... `Request.ServerVariables()` or `Session("ID")` or `Request.QueryString("ID")` or `Request.Form("ID")`??? – Rich Apr 04 '14 at 14:51
  • Is clientid a string? What's the value of Request("ID"), is it empty? Debugging ASP is not that simple. I always use the debug prints like mentioned by Peter... – kloarubeek Apr 04 '14 at 15:00
  • other debugging tips: http://stackoverflow.com/questions/1138175/how-do-you-debug-classic-asp – kloarubeek Apr 04 '14 at 15:22
  • Ok, figured out this particular error. I had missed a line to specify a case within a switch which was causing the SQL to query before there was a value for Request("ID") so the string was building with a null value. Thank you for your help though. koarubeek I will give that post a look and try some of what it suggests, thank you. – Dead_Jester Apr 04 '14 at 16:09

3 Answers3

1

Place following:

response.write Request("ID") & "<br>"
response.write SQL

before you call execute SQL Second make sure that your Request("ID") returns number other way your SQL should look like this:

SQL = "SELECT firstname,lastname FROM clientinfo WHERE ClientID = '" & Request("ID") & "'"

loose the brackets because ClientID is not the SQL reserved name.

About debugging classic ASP(VBScript) pages: only way to debug those suckers is to use response.write or move to NET framework which is out of question for you. There are lot of tools which claims that they will allow you to debug Classic ASP pages: do not waste your money and time.

*ADDED: **For debugging period you should also remove "on error resume next" from your pages and do Option Explicit. First will allow you to see where error occurs and second, while making your life a bit harder, will prevent some of the errors because it will not allow you to use any undeclared variables.

All Blond
  • 802
  • 1
  • 8
  • 16
0

Judging by the filename "test.asp" it looks to me like you are using ASP and not ASP.NET. I don't know if this is your intention? ASP.NET can be debugged by attaching a debugger (for example Visual Studio) to IIS's worker process (usually w3wp.exe).

  • Honestly as I am new to this whole thing, I thought they were much the same thing. Changed title though. Thank you – Dead_Jester Apr 04 '14 at 14:06
  • ASP is very old and runs script, whereas ASP.NET can also be compiled. If you are used to working in Java then ASP.NET makes more sense in my opinion. – Wouter van der Neut Apr 04 '14 at 14:08
  • Normally I would agree with you but unfortunately in this case I am trying to add a new page to an existing server that I help manage but do not own, so changing that language it is written in is kind of out of the question (The server is rather large as well so it would take months to translate, my deadline is in 2 weeks). – Dead_Jester Apr 04 '14 at 14:11
0

ASP or ASP.NET, in both cases you can use a simple logging to a file to debug. Add this to your asp page of common used procedures, i call it routines.asp

and in your page you want to debug you add

<!--#include file="routines.asp"-->

then call the sub when you need it

call debug page, line, varname, varcontents

where page=the name of the asp file and possibly of the procedure or function being executed, line=the linenummer where you call debug, varname and varcontents the name and the variable itself, the first two parameters make it easy to find the source of the logging

eg

call debug "myApp.asp/getOLEdata", "122", "SQL", SQL
peter
  • 41,770
  • 5
  • 64
  • 108