Double Insert?

  • Hello,

    I have a asp.net application hooked up to SQL Server 2005. The .net app calls a stored procedure on sql server which looks like this:

    ALTER PROCEDURE [dbo].[p_SaveRepairStage]

    @stageID bigint OUTPUT,

    @repairID bigint,

    @stageType tinyint,

    @result tinyint,

    @userid varchar(50),

    @station varchar(50),

    @endDate datetime=null,

    @comments varchar(500),

    @lastTestStageID bigint

    AS

    if (@stageID=-1)

    begin

    INSERT INTO SystemRepairStage

    (

    RepairID,

    StageType,

    Result,

    UserID,

    Station,

    EndDate,

    Comments,

    LastTestStageID

    )

    VALUES

    (

    @repairID,

    @stageType,

    @result,

    @userid,

    @station,

    @endDate,

    @comments,

    @lastTestStageID

    )

    SET @stageID=IDENT_CURRENT('SystemRepairStage')

    end

    else

    begin

    UPDATE SystemRepairStage SET

    Result=@result,

    EndDate=@endDate,

    Comments=@comments

    WHERE StageID=@stageID and RepairID=@repairID and EndDate is null

    end

    Every now and then (and it is very sporadic) I get duplicated records that look like the example below.

    Not always the same number of them (i was only expecting to insert 1)

    Please note the StartDate (the column is defaulted to GetDate())

    StageIDRepairIDStageTypeResultStartDateUserIDEndDateCommentsLastTestStageIDStation

    1051324305259102009-03-24 10:31:29.720phanyv2009-03-24 13:51:02.400no videoNULLCR-TEST1

    1051331305259102009-03-24 10:31:29.783phanyv2009-03-24 13:51:19.307no videoNULLCR-TEST1

    1051332305259112009-03-24 10:31:29.783phanyvNULLNULLNULLCR-TEST1

    Has anyone ever seen anything like this ? Am i doing something wrong here or is it sql server?

  • Duplicate post, Replies here please.

    [font="Arial"]---

    Mohit K. Gupta, MCITP: Database Administrator (2005), My Blog, Twitter: @SQLCAN[/url].
    Microsoft FTE - SQL Server PFE

    * Some time its the search that counts, not the finding...
    * I didn't think so, but if I was wrong, I was wrong. I'd rather do something, and make a mistake than be frightened and be doing nothing. :smooooth:[/font]

    How to ask for help .. Read Best Practices here[/url].

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply