?
Solved

ASP / VBScript Function Errors

Posted on 2012-04-12
11
Medium Priority
?
446 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:John Easton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37836464
0
 
LVL 11

Author Comment

by:John Easton
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 53

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 11

Author Comment

by:John Easton
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 53

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
 
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 2000 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 11

Author Comment

by:John Easton
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

752 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