Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling? 2

Status
Not open for further replies.

cLFlaVA

Programmer
Jun 14, 2004
6,450
US
Hi.

Is there a way to determine if the Err object is "enabled" (for lack of a better term)?

I am trying to force an error calling a stored prodedure that doesn't exist. I have [tt]On Error Resume Next[/tt] at the top of the page, and this directly after the [tt].Execute[/tt] call:

Code:
    If Err.Number <> 0 Then
        strError = Err.Description
    End If

however, strError is always blank. When I comment out the On Error Resume Next, the page barfs, showing me the expecting "stored procedure does not exist" error.

what's up with this?



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Generally speaking, an error has been raised if [tt]Err.Number <> 0[/tt]

It seems like you are describing a situation where the [tt].Number[/tt] property was set when the error was raised but the [tt].Description[/tt] property was not.


PS: The error message regarding the stored procedure makes me wonder if this is not perhaps an error that can be discovered by checking the [tt].Errors[/tt] collection property of your ADO connection object.

Assuming an ADO connection named [tt]adoCN[/tt]
[tt]
Dim foo
For Each foo In adoCN.Errors
Response.Write foo.Number & " " & foo.Description & " " & foo.Source
Response.Write "<br />" & vbCrLf
Next
Set foo = Nothing[/tt]


or you could also just do:[tt]
if adoCN.Errors.Count > 0 then
Response.Write "ADO connection error(s) <br>" & vbCrLf
end if
[/tt]
 
Hi Sheco...

no dice.

with this:

Code:
    Dim strSql

    strSql = "exec copy_budget_and_release_baseline " & strYear
    con.Execute strSql, 1, adCmdText
    if con.Errors.Count > 0 then
        strError =  "ADO connection error(s) <br>" & vbCrLf
    else
        strError = "blah"
    end if

if i comment out "On Error Resume Next" i get the ugly error page saying permission denied. if i un-comment the on error statement, strError is empty (length of 0). if i then comment out the execute statement, strError is "blah".

what gives?



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
OK so you are saying that all of the following are true:

1. [tt]con.Errors.Count = 0[/tt]
2. [tt]err.Number <> 0[/tt]
3. [tt]err.Description = ""[/tt]

Oh, and do you have the constant adCmdText defined? Maybe in an adovbs.inc file? Might try adCmdStoredProc instead.

Another line of thought is maybe the stored procedure actually does not exist... at least not in the current database. Perhaps the ADO connection string is defaulting you to a different database?


 
p.s. - i am forcing it to fail with a misnamed stored procedure, and/or permissioning rights. now, when i do this, i don't even get a printout of those values when i have this in my code:

Code:
    strSql = "exec copy_budget_and_release_basline " & strYear
    con.Execute strSql, 1, adCmdText
    
    response.write "1. con.Errors.Count = " & con.Errors.Count & "<br />"
    response.write "2. err.Number = " & err.Number & "<br />"
    response.write "3. err.Description = " & err.Description & "<br />"

nothing shows up. on error resume next is not commented out.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
That is bizzare. I tried this...

Code:
On Error Resume Next
strSql = "exec copy_budget_and_release_basline " & strYear
DB.Execute strSql, 1, adCmdText
                
response.write "1. con.Errors.Count = " & DB.Errors.Count & "<br />"
response.write "2. err.Number = " & err.Number & "<br />"
response.write "3. err.Description = " & err.Description & "<br />"

Notice that I changed con to DB, but otherwise it is identical. I get...

[tt][blue]1. con.Errors.Count = 1
2. err.Number = -2147217900
3. err.Description = Could not find stored procedure 'copy_budget_and_release_basline'.[/blue][/tt]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
is there an on error statement i can place directly after the execute call that will allow the standard error display to occur? maybe i'm getting an error on one of the 1.2.3. lines that is being suppressed?



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Cory,

Do you have a variable named ERR somewhere?

Code:
On Error Resume Next
                
[!]Dim err[/!]
                
strSql = "exec copy_budget_and_release_basline " & strYear
DB.Execute strSql, 1, adCmdText
                
response.write "1. con.Errors.Count = " & DB.Errors.Count & "<br />"
response.write "2. err.Number = " & err.Number & "<br />"
response.write "3. err.Description = " & err.Description & "<br />"

With the err variable, lines 2 and 3 don't show.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
this is embarrassing.

here's my entire file. i added on error resume next inside the function, and it seems to work fine now.

i apologize for wasting everyone's time.

Code:
<%
On Error Resume Next

strAction = Request.Form("hdnAction")

Public strYear
Public strMessage

strYear = Request.Form("cboCopyYear")

'determine appropriate course of action
Select Case strAction
	Case "Close"
		Response.Redirect(getPreviousFromNavStack)	
	Case "Copy"
        Call doCopy( strYear )
		addSelfToNavStack("frmBudgetLoading.asp")
End Select

Private Sub doCopy( strYear )
    On Error Resume Next
    %><!-- #include file="connect.asp" --><%

    Dim strSql

    strSql = "exec copy_budget_and_release_basline " & strYear
    con.Execute strSql, 1, adCmdText

    'response.write "1. con.Errors.Count = " & con.Errors.Count & "<br />"
    response.write "2. err.Number = " & err.Number & "<br />"
    response.write "3. err.Description = " & err.Description & "<br />"
    response.write "3. err.Description = " & "test" & "<br />"
    
    if con.Errors.Count > 0 then
        strMessage =  "ADO connection error(s) <br>" & vbCrLf
    else
        strMessage = "<font class=""FONTcontrollabelbold"">Completed</font>"
    end if

    %><!-- #include file="disconnect.asp" --><%
End Sub

%>

i thought the one on error up top was enough. now i get the expected error message. sorry again.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Ah.... Don't be embarrassed.

I learned something because of this. I didn't know that I couldn't do it the way that I wasn't. [smile]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top