1

This is driving my crazy. I get an error ("500 - Internal server error.") on my web page when returning from this sub. It executes just fine and does what it's supposed to do: add a record of a user (MemID) to the Chat table for an event (EventID) if it hasn't already been added. The first query is to find out if there's already a record. If not, the INSERT statement adds a record. The error occurs after the sub has run.

Sub NewView (EventID)
    MemID=Session("MemID")
    
    If MemID>0 then
        Set cn5=Server.CreateObject("ADODB.connection")
        cn5.open application("gbConnect")    
        SQL="SELECT Chat.MemID, Chat.EventID FROM Chat WHERE Chat.MemID=" & MemID & " AND Chat.EventID=" & EventID & ";"  
        cn5.cursorLocation=3

        Set Rst=cn5.execute(SQL)
        
        If Rst.recordcount = 0 then
            Comment="is watching"
            SQL="INSERT INTO Chat ( MemID, EventID, Comment ) SELECT " & MemID & "," & EventID & ", '" & Comment & "';"
            cn5.execute(SQL)
            Set cn5=nothing
        End If
    End If 
End Sub

On the page: NewView (EventID) 'Returning from this sub causes an error! "500 - Internal server error."

Étienne Laneville
  • 4,697
  • 5
  • 13
  • 29
Kwixster
  • 51
  • 8
  • 1
    Does this answer your question? [Detailed 500 error message, ASP + IIS 7.5](https://stackoverflow.com/questions/2640526/detailed-500-error-message-asp-iis-7-5) – user692942 Sep 13 '20 at 22:21
  • Enabling detailed errors should provide the exact line that caused the error, without it no one will be able to help. – user692942 Sep 13 '20 at 22:22

1 Answers1

1

OK. I figured it out. I got a lesson in scope of variables. Setting the variable Rst (recordset) in the sub ruined the same variable on the main page. Now just have to wait for my hair to grow back.

Kwixster
  • 51
  • 8
  • 1
    `Option Explicit` is your friend, you shouldn't use variables without `Dim` (especially in a `Sub` or `Function`). – user692942 Sep 13 '20 at 23:29