superman74
Technical User
I'm new at attempting Error handling, as well as subs. I'm doing the best I can in following along with ASP Bible.
Here's what I have for the ERROR HANDLER:
<%
'LEADS DATABASE CONNECTION ==============================
Set Conn = Server.CreateObject("ADODB.Connection"
Conn.Open "dsn"
'ERROR HANDLING =========================================
Sub HandleError(strLocation)
if Err.Number = 0 then Exit Sub
%>
<table>
<tr>
<td><h3>Page Error</h3></td>
</tr>
<tr>
<td width="17%"><b>Error #:</b></td>
<td width="83%"><%=Err.Number%></td>
</tr>
<tr>
<td width="17%"><b>Description:</b></td>
<td width="83%"><%=Err.Description%></td>
</tr>
<tr>
<td width="17%"><b>Source:</b></td>
<td width="83%"><%=Err.Source%></td>
</tr>
<tr>
<td width="17%"><b>URL:</b></td>
<td width="83%"><%=Request.ServerVariables("URL"%></td>
</tr>
<tr>
<td width="17%"><b>Location:</b></td>
<td width="83%"><%=strLocation%></td>
</tr>
</table>
</body>
</html>
<%
Response.End
End Sub
%>
I'm somewhat confused with how to actually run it on the page I'm testing. I have the above handler added in an include. I thought I was suppose to add "HandleError(strLocation" where ever I wanted to check for an error, like below (I'm sure someone will scold me for being sloppy - I'm learning):
<%
On Error Resume Next
'RETRIEVE LOGIN ID ======================================
IDSql="SELECT TOP 1 * FROM tblLogins WHERE Name = " & sName
Set rsID=Conn.Execute(IDSql)
'ERROR SUB
HandleError("Retrieve Login ID"
do while not rsID.eof
strLoginID = rsID("LoginID"
rsID.movenext
loop
rsID.close
'GET TODAYS DATE
datDate = Now()
strDate = FormatDateTime(datDate, 2)
'CREATE RECORDSET =======================================
Set RS = Server.CreateObject( "ADODB.Recordset" )
RS.ActiveConnection = Conn
RS.CursorType = adOpenStatic
RS.LockType = adLockPessimistic
'Add New Entry To Database
RS.Open "SELECT * FROM tblLogin_Date WHERE DateID = ''"
RS.AddNew
'ERROR SUB
HandleError("Add Login Date entry"
RS( "LoginDate" ) = strDate
RS( "LoginID" ) = strLoginID
RS( "EmailFrom" ) = strFromDate
RS.Update
RS.Close
%>
I also have the HandleError() a few more places. When I purposely create an error by misspelling a table names somewhere, I get some very strange results. It displays the "Page Error" the next line "Error#", then drops down, moves over and does it again, over and over. I'm sure I'm doing something wrong, which is why I'm here.
Superman74 - knucklehead!!!
Here's what I have for the ERROR HANDLER:
<%
'LEADS DATABASE CONNECTION ==============================
Set Conn = Server.CreateObject("ADODB.Connection"
Conn.Open "dsn"
'ERROR HANDLING =========================================
Sub HandleError(strLocation)
if Err.Number = 0 then Exit Sub
%>
<table>
<tr>
<td><h3>Page Error</h3></td>
</tr>
<tr>
<td width="17%"><b>Error #:</b></td>
<td width="83%"><%=Err.Number%></td>
</tr>
<tr>
<td width="17%"><b>Description:</b></td>
<td width="83%"><%=Err.Description%></td>
</tr>
<tr>
<td width="17%"><b>Source:</b></td>
<td width="83%"><%=Err.Source%></td>
</tr>
<tr>
<td width="17%"><b>URL:</b></td>
<td width="83%"><%=Request.ServerVariables("URL"%></td>
</tr>
<tr>
<td width="17%"><b>Location:</b></td>
<td width="83%"><%=strLocation%></td>
</tr>
</table>
</body>
</html>
<%
Response.End
End Sub
%>
I'm somewhat confused with how to actually run it on the page I'm testing. I have the above handler added in an include. I thought I was suppose to add "HandleError(strLocation" where ever I wanted to check for an error, like below (I'm sure someone will scold me for being sloppy - I'm learning):
<%
On Error Resume Next
'RETRIEVE LOGIN ID ======================================
IDSql="SELECT TOP 1 * FROM tblLogins WHERE Name = " & sName
Set rsID=Conn.Execute(IDSql)
'ERROR SUB
HandleError("Retrieve Login ID"
do while not rsID.eof
strLoginID = rsID("LoginID"
rsID.movenext
loop
rsID.close
'GET TODAYS DATE
datDate = Now()
strDate = FormatDateTime(datDate, 2)
'CREATE RECORDSET =======================================
Set RS = Server.CreateObject( "ADODB.Recordset" )
RS.ActiveConnection = Conn
RS.CursorType = adOpenStatic
RS.LockType = adLockPessimistic
'Add New Entry To Database
RS.Open "SELECT * FROM tblLogin_Date WHERE DateID = ''"
RS.AddNew
'ERROR SUB
HandleError("Add Login Date entry"
RS( "LoginDate" ) = strDate
RS( "LoginID" ) = strLoginID
RS( "EmailFrom" ) = strFromDate
RS.Update
RS.Close
%>
I also have the HandleError() a few more places. When I purposely create an error by misspelling a table names somewhere, I get some very strange results. It displays the "Page Error" the next line "Error#", then drops down, moves over and does it again, over and over. I'm sure I'm doing something wrong, which is why I'm here.
Superman74 - knucklehead!!!