Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 6th, 2006, 02:02 PM
Registered User
 
Join Date: Jul 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Random Duplicate Entries

I have a problem that is driving me NUTS. I have this simple form with some shipping data, that I send to an asp file processshippingdetails.asp, the process scripts are there, and then the form redirects. Simple. In fact, in this application I am using the same code (copied the files and just changed the variables) to process a couple of other forms.

But this one form, its bizaare. Sometimes it creates duplicate entries. Same exact time stamp down to the second. No noticable lag in the processing. I know the button is not being hit twice because ive tested it carefully.

It doesnt happen every time - maybe about 40% of the time, I simply get two exact duplicates. Anyone seen this before? Any guesses? Because at this point I really have NO idea where else to go with this.

 
Old July 6th, 2006, 03:26 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It sounds to me that your code is somehow adding an extra, duplicate record to the database about 40% of the time.
Is this correct?

If so, there could be a number of problems. One place to start is to show us the code in procssshippingdetails.asp that does the inserting into the database.

Woody Z http://www.learntoprogramnow.com
 
Old July 7th, 2006, 08:56 AM
Registered User
 
Join Date: Jul 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, this is it. Please forgive the juvenile code...im not actually a programmer, im an office manager who learned to program to help out here and there!


<%
    Dim JobID, Carrier, CarrierID, objC, strC, Comments, shippingaddressID, city, state, strS, objS, cost, PLTSWeight, ShipDate, DelDate

    JobID = Request.Form("JobID")
    If NOT Request.Form("CarrierID") = "" Then
        CarrierID = Request.Form("CarrierID")
    Else
        Carrier = Request.Form("Carrier")

            Set objC = Server.CreateObject("ADODB.Recordset")
            strC = "SELECT * FROM Carrier"
            objC.Open strC, strConnect, adOpenKeyset, adLockOptimistic

            objC.MoveLast
            objC.AddNew
            objC("CarrierName") = Carrier
            objC.Update

            CarrierID = objC("CarrierID")
            objC.Close
    End IF

    Comments = Request.Form("Comments")

    ShippingAddressID = Request.Form("ShippingAddressID")
    If NOT ShippingAddressID = 0 Then
        Set objS = Server.CreateObject("ADODB.Recordset")
        strS = "SELECT * FROM ShippingAddressID =" & ShippingAddressID
        objS.Open strS, strConnect, adOpenKeyset, adLockOptimistic

        City = objS("City")
        State = objS("State")
    Else
        City = Request.Form("City")
        State = Request.Form("State")
    End If

    If NOT Request.Form("Quote") = "" Then
        Cost = Request.Form("Quote")
    Else
        Cost = 0
    End If
    PLTSWeight = Request.Form("Weight")
    ShipDate = Request.Form("pMonth") & "/" & Request.Form("pDay") & "/" & Request.Form("pYear")
    DelDate = Request.Form("dMonth") & "/" & Request.Form("dDay") & "/" & Request.Form("dYear")

    Dim objA, strA

    Set objA = Server.CreateObject("ADODB.Recordset")
    strA = "SELECT * FROM Shipments"
    objA.Open strA, strConnect, adOpenKeyset, adLockOptimistic

    objA.MoveLast
    objA.AddNew

    objA("Date") = Now
    objA("JobID") = JobID
    objA("CarrierID") = CarrierID
    objA("Cost") = Cost
    objA("DatetoShip") = ShipDate
    objA("DatetoArrive") = DelDate
    objA("PLTSWeight") = PLTSWeight
    objA("Comments") = Comments
    objA("City") = City
    objA("State") = State
    objA.Update
    objA.Close

If Request.QueryString("Action") = "another" Then
    Response.Redirect "shippingdetails.asp?action=another&JobID=" & JobID& "&CarrierID="& CarrierID
Else
    Response.Redirect "createshippingentry.asp"
End IF

%>

 
Old July 7th, 2006, 09:54 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well... the only place where it seems to me that another record could be getting created is in the following code if the shippingdetails.asp or createshippingentry.asp redirects have any code that saves a record during the serving of the page:

Code:
If Request.QueryString("Action") = "another" Then
    Response.Redirect "shippingdetails.asp?action=another&JobID=" & JobID& "&CarrierID="& CarrierID
Else
    Response.Redirect "createshippingentry.asp"
End IF
However, there seems to be some troubling code here.
For example, does this sql statement actually work???:

Code:
strS = "SELECT * FROM ShippingAddressID =" & ShippingAddressID
I can't imagine that is actually works without an error as that is a malformed sql statement.

Also, these bits of code could eventually become a serious performance issue:

Code:
...
strC = "SELECT * FROM Carrier"
...
strA = "SELECT * FROM Shipments"
...
You are retrieving ALL carriers or shipments just to insert a single carrier.
A better way to do is:
Code:
strC = "SELECT * FROM Carrier Where CarrierId = 0"
This will retrieve an empty recordset to which you can add a new record. NOTE: You will not want to use the objC.MoveNext line in this case.

Woody Z http://www.learntoprogramnow.com
 
Old July 7th, 2006, 10:36 AM
Registered User
 
Join Date: Jul 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The really troublesome line probably wouldnt work....its a function that I hope to use somewhere down the line, the data is not in place to ever have it called yet. But I did fix it. And thanks for the tip on the calling ID=0 thing....I taught myself from books and web queries and tend to make a lot of guesses at what will work!

I know its not the other pages. The ONLY asp on them is to fill in a drop down box. Just very weird. Perhaps with your suggestions it will work more smoothly.

Thanks!

 
Old July 7th, 2006, 05:40 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If this is the only code that can insert records into that table, I would suggest that it is possible that the user is using the back-button and clicking the submit button a second time. If this is the actual, working code then there is nothing here that I can see that would cause a duplicate entry to be created in the Shipments table.

Woody Z http://www.learntoprogramnow.com
 
Old July 16th, 2006, 10:47 PM
Authorized User
 
Join Date: Apr 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'd have to go agree with Woody on this. Just looking at your code, I don't see anywhere in it that would cause a duplicate record. Which table is the dupe appearing in? (or is it both?)

Also, are you absolutely positive that shippingdetails.asp and createshippingentry.asp have no asp code? No redirects or anything? That's about the only thing I can see that would cause an issue here too. Maybe when you see the duplicate record, see which page you were forwarded to. If it's the same page all the time, perhaps there is code in that page that is causing the issue.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing duplicate entries avantikad XSLT 2 January 2nd, 2008 12:29 PM
Validate duplicate Entries using javascript sams ASP.NET 1.0 and 1.1 Professional 3 July 2nd, 2007 03:31 AM
How not to retrieve duplicate entries? EricTheViking Access ASP 2 January 12th, 2007 08:22 AM
How can I check for duplicate entries in XML gargkapil777 XSLT 2 December 22nd, 2005 01:00 PM
Delete duplicate entries from table expertcalling SQL Server 2000 2 January 2nd, 2005 11:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.