Solved

ASP / VBScript Function Errors

Posted on 2012-04-12
11
438 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

13 Experts available now in Live!

Get 1:1 Help Now