Solved

ASP / VBScript Function Errors

Posted on 2012-04-12
11
444 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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