I have two function:
The two function are in a Class named Pippo with this Inizializing New Function:
Sometimes, a user connect to my application and get this error (that I receive in my mail):
Etc.
I'm not figuring why this error occures and why it occures only sometimes...
Thank you for your help
Code:
Public Sub AddData()
Dim sSQL As String = ""
Dim check As Boolean = Me.TestExistingRow("QUESTIONARIO1")
If check = False Then
sSQL = "INSERT INTO QUESTIONARIO1([USER]) VALUES ('" &
Me.IdUser & "');"
ExecuteNonQuery(Me.ConnString, CommandType.Text, sSQL)
End If
End Sub
Public Function TestExistingRow(ByVal NameTable As String) As Boolean
Dim sSQL As String = ""
Dim n As Integer = 0
Dim check As Boolean = True 'la riga esiste
sSQL = "SELECT Count([USER]) as tot FROM " & NomeTabella & " where [USER]='" & Me.IdUser & "';"
Try
n = CInt(ExecuteScalar(Me.ConnString, CommandType.Text, sSQL))
If n = 0 Then
check = False
End If
Catch ex As Exception
check = True
End Try
Return check
End Function
Code:
Public Sub New(ByVal p As Page, ByVal c As HttpContext)
SyncLock (Me)
Me.IdUser = "VOID"
If Not p.Request.Params("IdUser") Is Nothing Then Me.IdUser = p.Request.Params("IdUser").ToString
If ((Not c.User Is Nothing) And (Me.IdUser = "VOID" Or Me.IdUser = "")) Then Me.IdUser = HttpContext.Current.User.Identity.Name
If Me.IdUser = "" Then Me.IdUser = "VOID"
Me.ConnString = Me.GetCN()
End SyncLock
End Sub
Violation of PRIMARY KEY constraint 'PK__QUESTION__ AA65E05E1881A0D E'. Cannot insert duplicate key in object 'dbo.QUESTIONAR IO1'.
The statement has been terminated.
[...]
AUTH_TYPE = Forms
AUTH_USER = BL0210
AUTH_PASSWORD =
LOGON_USER =
REMOTE_USER = BL0210Etc.
I'm not figuring why this error occures and why it occures only sometimes...
Thank you for your help
Comment