Thread was being aborted. Maar waarom? (VB.NET, ASP)

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

  • Psycho_Mantis
  • Registratie: Februari 2007
  • Laatst online: 04-07 12:38

Psycho_Mantis

Wow. So Amaze.

Topicstarter
Heel vreemd, op een stukje code wat gewoon super simpel is krijg ik een Exception:

Het SQL record word wel geüpdatet, maar geeft echter de melding Thread was being aborted.
Als ik op internet zoek, komt dit probleem eigenlijk alleen maar voor als het te lang duurt om een SQL record te updaten. Dit is alleen niet het geval, want het is slechts 1 record.

Ik ben misschien nog niet helemaal wakker vandaag en ziet iemand anders wel wat ik fout heb gedaan. :?

Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Try
            ' update database with new stock level
            Dim conL As New SqlConnection
            Dim cmdL As New SqlCommand
            conL.ConnectionString = "(eventjes verborgen)"
            conL.Open()
            cmdL.Connection = conL
            cmdL.CommandText = "UPDATE Category SET Product_Category_Quantity=@Product_Category_Quantity WHERE Product_Category_ID=@Product_Category_ID"
            cmdL.Parameters.AddWithValue("@Product_Category_Quantity", StockLvlReal.Text)
            cmdL.Parameters.AddWithValue("@Product_Category_ID", CatagoryID.Text)
            cmdL.ExecuteNonQuery()
            conL.Close()
            ' end of update stock level

            Session("ResultMessage") = "Stock level has been synced"
            Session("ReturnPage") = "Stock_Count.aspx"
            Session("ErrorLevel") = "ok"
            Dim url = "result.aspx"
            Response.Redirect(url)
        Catch ex As Exception
            Session("ResultMessage") = ex.Message
            Session("ReturnPage") = "Stock_Count.aspx"
            Session("ErrorLevel") = "error"
            Dim url = "result.aspx"
            Response.Redirect(url)
        End Try
    End Sub

Acties:
  • 0 Henk 'm!

  • Alex)
  • Registratie: Juni 2003
  • Laatst online: 04-07 10:37
Als ik op internet zoek, komt dit probleem eigenlijk alleen maar voor als het te lang duurt om een SQL record te updaten. Dit is alleen niet het geval, want het is slechts 1 record.
Dat hoeft niet zo zeer het geval te zijn. Als er bijvoorbeeld een index op die table staat, heeft dit invloed op de performance van je UPDATE-statement. Ook de aanwezigheid van bijvoorbeeld triggers kan iets betekenen.

Met SQL Server Profiler kun je precies in de gaten houden, wat er aan de serverkant gebeurt. Als er timeouts optreden aan de SQL-kant krijg je dat te zien.

Het hoeft niet aan de SQL-kant te liggen, een ThreadAbortException wordt namelijk gegooid door Response.Redirect, dit wordt gedaan om te voorkomen dat er nog andere code runt en (mogelijk) output naar de client. Erg netjes is dit niet, zie ook deze StackOverflow-thread.

We are shaping the future


Acties:
  • 0 Henk 'm!

  • Sebazzz
  • Registratie: September 2006
  • Nu online

Sebazzz

3dp

Zou je kunnen aangeven waar de fout voorkomt?

[Te koop: 3D printers] [Website] Agile tools: [Return: retrospectives] [Pokertime: planning poker]


Acties:
  • 0 Henk 'm!

  • Psycho_Mantis
  • Registratie: Februari 2007
  • Laatst online: 04-07 12:38

Psycho_Mantis

Wow. So Amaze.

Topicstarter
Inderdaad de Response.Redirect(url) was het probleem. het werkt nu bedankt! :)
Heb het even een stukje naar onder verplaatst zoals in de onderstaande code:
Dit was mogelijk omdat je de melding "Stock level has been synced" nooit zou zien als er een exception is.

Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Try
            ' update database with new stock level
            Dim conL As New SqlConnection
            Dim cmdL As New SqlCommand
            conL.ConnectionString = "(eventjes verborgen)"
            conL.Open()
            cmdL.Connection = conL
            cmdL.CommandText = "UPDATE Category SET Product_Category_Quantity=@Product_Category_Quantity WHERE Product_Category_ID=@Product_Category_ID"
            cmdL.Parameters.AddWithValue("@Product_Category_Quantity", StockLvlReal.Text)
            cmdL.Parameters.AddWithValue("@Product_Category_ID", CatagoryID.Text)
            cmdL.ExecuteNonQuery()
            conL.Close()
            ' end of update stock level


        Catch ex As Exception
            Session("ResultMessage") = ex.Message
            Session("ReturnPage") = "Stock_Count.aspx"
            Session("ErrorLevel") = "error"
            Dim url = "result.aspx"
            Response.Redirect(url)
        End Try

            Session("ResultMessage") = "Stock level has been synced"
            Session("ReturnPage") = "Stock_Count.aspx"
            Session("ErrorLevel") = "ok"
            Dim url = "result.aspx"
            Response.Redirect(url)

    End Sub


@Sebazzz, de melding kwam uit de ex.message