ASP SQL Error Handling

I am using Classic asp and SQL Server 2005.

This is the code that works (provided by another member):

 sqlStr = "USE "&databaseNameRecordSet.Fields.Item("name")&";SELECT permission_name FROM fn_my_permissions(null, 'database')"

This code checks what permissions I have in this database - the problem is - if I do not have permission, it throws an error and does not continue to draw the rest of my page.

Anyone have any ideas on how to fix this?

Thanks a lot Joel

+3
source share
2 answers

Since VBScript does not support processing On Error GoTo <label>, you will need to useOn Error Resume Next

hasPermission = CheckPermission()

Function CheckPermission()
    On Error Resume Next
    '--- here goes your database query

    If Err.Number = 0 Then
        CheckPermission = True
    Else
        CheckPermission = False
    End If
End Function

If you use JScript, you can try / catch.

+2
source

, - ASP, . , .

On Error Resume Next

sqlStr = "USE "&databaseNameRecordSet.Fields.Item("name")&";SELECT permission_name FROM fn_my_permissions(null, 'database')"

rs.Open sqlStr, connection

If Err.Number <> 0 Then
    Response.Write "No Permissions"
Else
    ' Your code to display or process permissions
End If

On Error Goto 0
+2

Source: https://habr.com/ru/post/1747316/


All Articles