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?

  • double post.

    follow the suggested solutions hee to avoid disjointed answers:

    http://qa.sqlservercentral.com/Forums/Topic683311-266-1.aspx

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

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

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