Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > how to debug in asp ?

Reply
Thread Tools

how to debug in asp ?

 
 
Kim
Guest
Posts: n/a
 
      02-04-2008
Im generally new to ASP, so bear with me. This is not ASP (dot) NET.

I have a query which gives results when doing the it directly, but
none (maybe) when done in asp. "Maybe" because I can not get the query
to output anything.

sample code:
set results = conn.execute("Select field1, field2, field3 from tbl")

while results.EOF
response.write("before ")
response.write(results("field1"))
response.write(" after<br>")
response.end

results.movenext
wend

sample code result:
"before after"

sample code expected result:
"before <field1_value> after"

How can I debug this ?
I know the query is correct, and it gives results when running it
directly.
 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      02-04-2008
Kim wrote:
> Im generally new to ASP, so bear with me. This is not ASP (dot) NET.
>
> I have a query which gives results when doing the it directly, but
> none (maybe) when done in asp. "Maybe" because I can not get the query
> to output anything.
>
> sample code:
> set results = conn.execute("Select field1, field2, field3 from tbl")
>
> while results.EOF


Ummm ... I think you meant "WHILE NOT results.EOF"

Actually, While...Wend have been deprecated. It's more "accepted" these days
to use a Do loop:

Do Until results.EOF
...
Loop


> response.write("before ")
> response.write(results("field1"))
> response.write(" after<br>")
> response.end


Why are you using response.end here?

>
> results.movenext
> wend
>
> sample code result:
> "before after"


Really? I would expect no output at all if your While statement is written
as above (as long as the query returns results, that is)

>
> sample code expected result:
> "before <field1_value> after"


Again, as written, your code would never produce this result.

>
> How can I debug this ?
> I know the query is correct, and it gives results when running it
> directly.


What is the database? If SQL Server, use SQL Profiler to run a trace to
verify that the sql statement being sent to the server is the statement you
expect it to be. Otherwise, write your sql statement to Response to verify
that you have built it correctly. It's a good programming practice to assign
the statement to a variable so that it can be easily written to Response and
used as the <source> argument for the Execute method call.

More tips:
Using dynamic sql can leave you vulnerable to hackers using sql
injection:
http://mvp.unixwiz.net/techtips/sql-injection.html
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23

See here for a better, more secure way to execute your queries by using
parameter markers:
http://groups-beta.google.com/group/...e36562fee7804e

Personally, I prefer using stored procedures, or saved parameter queries
as they are known in Access:

Access:
http://www.google.com/groups?hl=en&l...TNGP12.phx.gbl

http://groups.google.com/groups?hl=e...tngp13.phx.gbl

Select statement:
http://groups-beta.google.com/group/...d322b882a604bd



SQL Server:

http://groups.google.com/group/micro...9dc1701?hl=en&


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
 
 
 
Kim
Guest
Posts: n/a
 
      02-04-2008
On Feb 4, 1:29 pm, "Bob Barrows [MVP]" <(E-Mail Removed)>
wrote:
> Kim wrote:
> > Im generally new to ASP, so bear with me. This is not ASP (dot) NET.

>
> > I have a query which gives results when doing the it directly, but
> > none (maybe) when done in asp. "Maybe" because I can not get the query
> > to output anything.

>
> > sample code:
> > set results = conn.execute("Select field1, field2, field3 from tbl")

>
> > while results.EOF

>
> Ummm ... I think you meant "WHILE NOT results.EOF"

Correct. It was a typo.

> Actually, While...Wend have been deprecated. It's more "accepted" these days
> to use a Do loop:
>
> Do Until results.EOF
> ...
> Loop
>
> > response.write("before ")
> > response.write(results("field1"))
> > response.write(" after<br>")
> > response.end

>
> Why are you using response.end here?

Debugging. To halt the script.

>
>
>
> > results.movenext
> > wend

>
> > sample code result:
> > "before after"

>
> Really? I would expect no output at all if your While statement is written
> as above (as long as the query returns results, that is)
>
>
>
> > sample code expected result:
> > "before <field1_value> after"

>
> Again, as written, your code would never produce this result.
>
>
>
> > How can I debug this ?
> > I know the query is correct, and it gives results when running it
> > directly.

>
> What is the database? If SQL Server, use SQL Profiler to run a trace to
> verify that the sql statement being sent to the server is the statement you
> expect it to be. Otherwise, write your sql statement to Response to verify
> that you have built it correctly. It's a good programming practice to assign
> the statement to a variable so that it can be easily written to Response and
> used as the <source> argument for the Execute method call.

Turns out the bugger was a missing space (!!). Hard to spot.

> More tips:
> Using dynamic sql can leave you vulnerable to hackers using sql
> injection:http://mvp.unixwiz.net/techtips/sql-....aspx?tabid=23
>
> See here for a better, more secure way to execute your queries by using
> parameter markers:http://groups-beta.google.com/group/...etserver.asp.d...
>
> Personally, I prefer using stored procedures, or saved parameter queries
> as they are known in Access:
>
> Access:http://www.google.com/groups?hl=en&l...8&selm=e6lLVvO...
>
> http://groups.google.com/groups?hl=e...ff=1&selm=eHYx...
>
> Select statement:http://groups-beta.google.com/group/...etserver.asp.d...
>
> SQL Server:
>
> http://groups.google.com/group/micro...ver.asp.genera...
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"


For the record, its MSSQL.
And its not my system. I have just been asked to add some new stuff
into it, so I have continued to use the same path as the majority of
the code is written in.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
debug="false" in web.config and <%@ debug="true" ...%> in aspx file => true or false? André ASP .Net 3 08-28-2006 12:02 PM
Config Mgr Debug/Release and Web.config Compilation debug=true RonL ASP .Net 0 04-08-2006 03:50 PM
Debug (DLL MFC) -> Debug (Static MFC) ringos75 C++ 0 04-14-2005 01:50 PM
[Howto] Compiling debug Python extensions for non-debug Python Mike C. Fletcher Python 3 10-12-2003 09:37 PM



Advertisments