Bug #33959 CONNECTOR DUPLICATE ENTRIES IN ASP .NET
Submitted: 21 Jan 2008 16:31 Modified: 29 Jan 2008 19:28
Reporter: Jorge Aceves Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.0 OS:Windows (Windows Vista)
Assigned to: CPU Architecture:Any
Tags: asp.net, connector, duplicate, ENTRIES

[21 Jan 2008 16:31] Jorge Aceves
Description:
Hi,

Im having a little bit of a problem, because I have coded in three different ways to do the same thing - INSERT A RECORD IN ASP .NET - and if I use ODBC or ADO it works fine, but if I use the Connector (Version 5.0) at the execution of it, I get two records with the same information instead of one. (The record gets duplicated).

I have only one instruction to insert the record and its called once, then I close the connection and set the connection to nothing. 

I tried a code from a MySQL Book and still create duplicated records.

I have Visual Studio 2005 and Windows Vista Home Basic Edition.

Thank you very much.

How to repeat:
Try this on VS 2005 and Windows Vista.

Create a new Mysql Connection
Insert with ?Values
Set Up parameters with Addwithvalue and '?' 
Executenonquery
close the connection
setup all of your variables to nothing
[22 Jan 2008 7:04] Jorge Aceves
This is the code that produces the error:

This is the code that creates a duplicate entry of the record.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim StrFilename As String
        StrFilename = File1.PostedFile.FileName
        StrFilename = System.IO.Path.GetFileName(StrFilename)
        File1.PostedFile.SaveAs(Server.MapPath("~/images/") + StrFilename)

        Dim File As String

        File = "~/images/" + StrFilename

        'Conexión BD - Mysql connector
        Dim Conexion = New MySqlConnection
        Try
            Conexion = New MySqlConnection("Data Source=localhost;Initial Catalog=imagenes; User ID=root; PWD=1234;")
            
        
            Conexion.open()
        Catch myerror As MySqlException
            MsgBox("Connectivity Error: " & myerror.Message)

        End Try

        'Save Record
       

        Dim com As New MySqlCommand
        com.Connection = Conexion
        com.CommandText = "insert into path (Imagen) values (?imagen)"
        com.Parameters.AddWithValue("?imagen", Archivo)
        com.ExecuteNonQuery()

        'Fin de Conexion
        Try
            Dim number
            number = com.ExecuteNonQuery()

        Catch ex As Exception

            'Send to another page explaining there was an error with the transaction

        Finally

        End Try
        Conexion.close()

        Conexion = Nothing
        com = Nothing

    End Sub
[29 Jan 2008 17:33] Reggie Burnett
Your code is calling ExecuteNonQuery twice.  This will cause two records to be inserted (assuming no pk conflict)
[29 Jan 2008 19:28] Jorge Aceves
Thank you very much, I didnt noticed that I was executing the query twice, I tried to look  for something that was repeated, but maybe because of the frustration I didnt see it.   Thank you very much.  And sorry for wasting your time.

Sinceraly

Jorge