Insertion en double ASP.NET

Cela me rend fou cette semaine dernière. J'ai lu beaucoup de questions et de réponses concernant ce problème mais je ne peux toujours pas résoudre mon problème. J'ai vérifié tous les events possibles déclenchés et n'en trouve aucun.

J'ai kondisi.aspx :

 <!-- some header here --> <form id="form1" runat="server" class="form-horizontal"> <div class="box-body"> <div class="form-group"> <label class="col-sm-2 control-label text-right">Kondisi :</label> <div class="col-sm-10"> <asp:textbox id="tbkondisi" runat="server" cssclass="form-control" textmode="MultiLine"></asp:textbox> </div> </div> <asp:label id="lInfo" runat="server" cssclass="error" visible="False"></asp:label> <asp:label id="linfoberhasil" runat="server" cssclass="berhasil" visible="False"></asp:label> <div class="box-footer text-center"> <dxe:aspxbutton id="btSimpan" runat="server" text="Simpan" cssclass="btn btn-primary" enabledefaultappearance="False"></dxe:aspxbutton> <dxe:aspxbutton id="btBatal" runat="server" text="Reset" cssclass="btn btn-danger" enabledefaultappearance="False"></dxe:aspxbutton> </div> <asp:hiddenfield id="hfID" runat="server" /> <asp:hiddenfield id="hfMode" runat="server" /> <!-- some grid and footer here --> 

L'événement de clic btSimpan qui a manipulé le button est:

 Protected Sub btSimpan_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btSimpan.Click Try If Validasi() Then If hfMode.Value = "Insert" Then Insert() linfoberhasil.Visible = True linfoberhasil.Text = "Simpan Berhasil" Else Update(hfID.Value) linfoberhasil.Visible = True linfoberhasil.Text = "Update Berhasil" End If End If Catch ex As Exception Response.Write("<b>Error button simpan :</b>" & ex.ToSsortingng) End Try End Sub 

C'est la fonction de validation qui vérifie l'article en double:

 Private Function Validasi() As Boolean Try clear_label() If hfMode.Value = "Insert" Then If tbkondisi.Text.Trim = "" Then lInfo.Visible = True lInfo.Text = "Nama kondisi masih kosong" Return False End If sqlssortingng = "SELECT ID FROM KondisiPengiriman " & _ "WHERE Nama_Kondisi = '" & tbkondisi.Text.Replace("'", "''") & "' " & _ "AND [status] = 1 " result = SQLExecuteScalar(sqlssortingng) If result <> "" Then lInfo.Visible = True lInfo.Text = "Nama kondisi sudah ada" Return False End If End If If hfMode.Value = "Update" Then If tbkondisi.Text.Trim = "" Then lInfo.Visible = True lInfo.Text = "Nama kondisi masih kosong" Return False End If End If Return True Catch ex As Exception Throw New Exception("Error function Validasi : " & ex.ToSsortingng) End Try End Function 

Et voici la fonction clear_label () qui réinitialise tous les champs:

 Private Sub clear_label() lInfo.Visible = False lInfo.Text = "" linfoberhasil.Visible = False linfoberhasil.Text = "" End Sub 

Et enfin la fonction insert ():

 Private Sub Insert() Try sqlssortingng = "INSERT INTO KondisiPengiriman " & _ "(Nama_Kondisi, UserName, [status]) VALUES " & _ "('" & tbkondisi.Text.Replace("'", "''") & "', '" & Session("UserId") & "', 1)" hasil = SQLExecuteNonQuery(sqlssortingng) If hasil > 0 Then load_grid_kondisi() clear() End If Catch ex As Exception Throw New Exception("<b>Error function insert :</b> " & ex.ToSsortingng) End Try End Sub 

Semble validation () juste touché une fois et il inséré 2 fois, et c'est ainsi que SQL traçage lors de l'insertion:

 RPC:Completed exec sp_reset_connection .Net SqlClient Data Provider sa 0 0 0 0 15032 55 2017-06-13 10:36:28.910 2017-06-13 10:36:28.910 0X00000000000000002600730070005F00720065007300650074005F0063006F006E006E0065006300740069006F006E00 sa ts11pc TS11PC Audit Login -- network protocol: LPC SQL:BatchStarting SELECT ID FROM KondisiPengiriman WHERE Nama_Kondisi = 'tes' AND [status] = 1 .Net SqlClient Data Provider sa 15032 55 2017-06-13 10:36:28.910 sa ts11pc TS11PC SQL:BatchCompleted SELECT ID FROM KondisiPengiriman WHERE Nama_Kondisi = 'tes' AND [status] = 1 .Net SqlClient Data Provider sa 0 2 0 0 15032 55 2017-06-13 10:36:28.910 2017-06-13 10:36:28.910 sa ts11pc TS11PC Audit Logout .Net SqlClient Data Provider sa 0 1782 0 3 15032 55 2017-06-13 10:36:28.910 2017-06-13 10:36:28.913 1 - Non-DAC sa ts11pc TS11PC RPC:Completed exec sp_reset_connection .Net SqlClient Data Provider sa 0 0 0 0 15032 55 2017-06-13 10:36:28.913 2017-06-13 10:36:28.913 0X00000000000000002600730070005F00720065007300650074005F0063006F006E006E0065006300740069006F006E00 sa ts11pc TS11PC Audit Login -- network protocol: LPC SQL:BatchStarting INSERT INTO KondisiPengiriman (Nama_Kondisi, UserName, [status]) VALUES ('tes', 'LIGITAADMIN', 1) .Net SqlClient Data Provider sa 15032 55 2017-06-13 10:36:28.913 sa ts11pc TS11PC SQL:BatchCompleted INSERT INTO KondisiPengiriman (Nama_Kondisi, UserName, [status]) VALUES ('tes', 'LIGITAADMIN', 1) .Net SqlClient Data Provider sa 0 4 0 0 15032 55 2017-06-13 10:36:28.913 2017-06-13 10:36:28.913 sa ts11pc TS11PC Audit Logout .Net SqlClient Data Provider sa 0 1786 0 0 15032 55 2017-06-13 10:36:28.913 2017-06-13 10:36:28.913 1 - Non-DAC sa ts11pc TS11PC RPC:Completed exec sp_reset_connection .Net SqlClient Data Provider sa 0 0 0 0 15032 55 2017-06-13 10:36:28.913 2017-06-13 10:36:28.913 0X00000000000000002600730070005F00720065007300650074005F0063006F006E006E0065006300740069006F006E00 sa ts11pc TS11PC Audit Login -- network protocol: LPC SQL:BatchStarting INSERT INTO KondisiPengiriman (Nama_Kondisi, UserName, [status]) VALUES ('tes', 'LIGITAADMIN', 1) .Net SqlClient Data Provider sa 15032 55 2017-06-13 10:36:28.913 sa ts11pc TS11PC SQL:BatchCompleted INSERT INTO KondisiPengiriman (Nama_Kondisi, UserName, [status]) VALUES ('tes', 'LIGITAADMIN', 1) .Net SqlClient Data Provider sa 0 4 0 0 15032 55 2017-06-13 10:36:28.913 2017-06-13 10:36:28.913 sa ts11pc TS11PC Audit Logout .Net SqlClient Data Provider sa 0 1790 0 3 15032 55 2017-06-13 10:36:28.917 2017-06-13 10:36:28.920 1 - Non-DAC sa ts11pc TS11PC RPC:Completed exec sp_reset_connection .Net SqlClient Data Provider sa 15 0 0 0 15032 55 2017-06-13 10:36:28.920 2017-06-13 10:36:28.920 0X00000000000000002600730070005F00720065007300650074005F0063006F006E006E0065006300740069006F006E00 sa ts11pc TS11PC Audit Login -- network protocol: LPC SQL:BatchStarting SELECT ID, Nama_Kondisi from KondisiPengiriman where [status] = 1 .Net SqlClient Data Provider sa 15032 55 2017-06-13 10:36:28.920 sa ts11pc TS11PC SQL:BatchCompleted SELECT ID, Nama_Kondisi from KondisiPengiriman where [status] = 1 .Net SqlClient Data Provider sa 0 2 0 0 15032 55 2017-06-13 10:36:28.920 2017-06-13 10:36:28.920 sa ts11pc TS11PC Audit Logout .Net SqlClient Data Provider sa 0 1792 0 354220 15032 55 2017-06-13 10:36:28.920 2017-06-13 10:42:23.140 1 - Non-DAC sa ts11pc TS11PC 

Je ne peux pas comprendre ce qui a causé cela, semble que la fonction exécute juste 1 fois mais la command d'insertion 2 fois. Aide et Guide pour résoudre ce problème vraiment apprécié. Merci beaucoup.

Je suis désolé, je pensais que SQLExecuteNonQuery(sqlssortingng) est une command embeddede. De toute évidence, c'est une fonction personnalisée qui vérifie deux noms d'instance pour le server de sauvegarde. Et dans les parameters, ce nom d'instance 2 pointant vers le même server, ce qui fait double insertion.

C'est fait maintenant en supprimant un nom d'instance. Je vous remercie.