Solved

ASP / VBScript Function Errors

Posted on 2012-04-12
11
437 Views
Last Modified: 2012-04-12
I am developing an application in ASP and have moved all my SQL statements into functions.  This is to allow me to log activity and create an audit trail.

Now whenever the SQL throws an error it references the line of the function that executes the SQL.  However, it is (almost) always the variables that have been sent to the function that have caused the error.  Unfortunately I don't always know where the function was called from.  Some pages reference update or insert function multiple times for different data.

I am therefore wasting a lot of time working out where the error originated from.  Is there any way to establish where the function was called from.  I could then use this to write it to the screen when there is an error.
0
Comment
Question by:JEaston
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37836464
0
 
LVL 10

Author Comment

by:JEaston
ID: 37836496
This appears (if I understand it correctly) be related to SQL stored procedures which I am not using.  The functions are in in the ASP code.  Basically now if I get an error it will look something like this:

error '80040e14'
/assets/inc_sys.asp, line 16

This is the line of the function (which is located in an include file).  Prior to using the function the error might have been:

error '80040e14'
finance.asp, line 354

Now this is the line that is actually calling the function now and sending the wrong data to the function.  I need to get the second page and line information to troubleshoot the error - not the first one which is what the web server returns.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 37836700
A temporary way you can debug what is happening is adding a bunch of response.writes in the main code and use some sequential order so you can track what is going on and where things are breaking.  


<%
' main page
response.write "*** STEP 1 ****"

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

response.write "*** STEP 2 ****"

' Code calling function 1
response.write "*** STEP 3 ****"

' Code calling  function 2

response.write "*** STEP 4 ****"

' Code calling function 3

response.write "*** STEP 5 ****"


%>
0
 
LVL 10

Author Comment

by:JEaston
ID: 37836727
That's essentially what I'm doing at present, but not so useful once the system is deployed.  Given I currently have over 700 database calls over nearly 100 pages (and growing) I was looking for a more advanced solution if one exists.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 37836744
Sure, you can switch that out for silently recording errors to a text file or your database with something like

http://www.powerasp.net/content/new/on-error-resume-next.asp
<%
Set ObjMyFile = CreateObject("Scripting.FileSystemObject")
Err.Clear
On Error Resume Next
LogFileName = "aspprotect.log"
LogFileDirectory = "c:\somedirectory"
 
'Open Text File.. If doesn't exist create it and append to it .. If exists just append to it
Set WriteMyData = ObjMyFile.OpenTextFile(LogFileDirectory & "\" & LogFileName,8,True)
RowHeaderString = Session("User_ID") & vbTab
RowHeaderString = RowHeaderString & Session("Username") & vbTab
RowHeaderString = RowHeaderString & NOW & vbTab
RowHeaderString = RowHeaderString & Request.ServerVariables("REMOTE_ADDR")
WriteMyData.WriteLine(RowHeaderString)
WriteMyData.Close
On Error GoTo 0
%>
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 23

Expert Comment

by:basicinstinct
ID: 37836745
you could attach a debugger and view the call stack...
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37836751
can't say i've ever done it with classic asp tho... this article reckons you can: http://msdn.microsoft.com/en-us/library/ms241740.aspx
0
 
LVL 10

Accepted Solution

by:
plummet earned 500 total points
ID: 37836891
You could add error trapping inside the function and also pass a reference to the calling procedure, so an on error goto statement would  write out the error code plus the calling proc reference. It would however mean changing all your new functions and all calls to them. Nothing comes free though!

If you want an example let me know.

Regards
John
0
 
LVL 10

Author Comment

by:JEaston
ID: 37837037
@basicinstinct:  It looks like this is only for .NET, although the article does refer to ASP.  I guess this is bad authoring of the article.

@padas: I assume this would then just log the error message I current get, i.e. the function location not the calling page.  I don't mind the application aborting when it comes across an error - but I need to know the source of the error, not the location of the SQL Execute statement.

 @plummet: I thought about that too.  But after just replacing all my SQL statements with function calls the thought does not appeal.  

I'm surprised that within a function you cannot query the source - a bit like the window.parent function in JavaScript.
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37837048
more like "arguments.callee" in javascript... don't think such a thing exists in vbscript
0
 
LVL 10

Expert Comment

by:plummet
ID: 37837053
I quite understand! It's the way I'd go though. No pain, no gain etc.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now