2011-08-12 6 views
1

테이블에 일부 행을 추가하는 저장 프로 시저가 있습니다. 매우 기본적인 것입니다. SQL Server Management Studio 내에서 저장 프로 시저를 실행하면 정상적으로 반환됩니다. 그러나 내 응용 프로그램 내에서 이것을 실행하고 LINQ를 통해 SP로 호출하면 SP에 들어간 것처럼 보이지만 SP 내에서 프로세스가 실패합니다. 동일한 매개 변수는 모두 똑같은 것처럼 보입니다.저장 프로 시저가 LINQ에서 실행될 때만 실패합니다.

나는 이것이별로 진행되지 않는다는 것을 알고있다.하지만이 문제를 일으킬만한 아이디어가있는 사람은 누구인가? 쿼리를 평가할 때

set ANSI_NULLS ON 
set QUOTED_IDENTIFIER ON 
GO 
ALTER procedure [dbo].[sp_PTS_Action_Hardware_Batch_Insert] (
@HdwString Varchar(Max), 
@UID  Varchar(15) 
) 
as 
Declare  @Success_Nbr Bit 
Select  @Success_Nbr = 0 
Declare  @Success_Desc Varchar(100) 
Declare  @Stuff   Varchar(200) 
Declare  @TLoc   BigInt 
declare  @retV   int 
--Declare @RLoc   BigInt 
Declare  @StartLoc  BigInt 
Declare  @SLen   BigInt 

Declare  @V Varchar(25) 
Declare  @P Varchar(50) 
Declare  @S Varchar(50) 
Declare  @L Varchar(50) 
Declare  @D Varchar(200) 
Declare  @F Varchar(4) 
Declare  @C Varchar(50) 
Declare  @M Varchar(50) 
Declare  @I Varchar(20) 
Declare  @Q Varchar(10) 
/* 
Declare  @Req_Voucher_Number varchar(25), 
Declare  @Part_Number  varchar(50), 
Declare  @Serial_Number  varchar(50), 
Declare  @Lot_Number   varchar(50), 
Declare  @Description  varchar(200),  
Declare  @Federal_Class_Code varchar(4), 
Declare  @Unit_Of_Issue  varchar(5), 
Declare  @Item_Code_ID  int, 
Declare  @Unit_Price   money, 
Declare  @Qty    decimal(7, 2), 
Declare  @UID    Varchar(15) 
*/ 
Declare  @Item_Code_ID  int 
Declare  @Unit_Price   money 
Declare  @Qty    decimal(7, 2) 

If IsNull(@HdwString,'') = '' 
    BEGIN 
    Select @Success_Desc = 'No Data Provided.' 
    Goto ExitProcedure 
    END 

If IsNull(CharIndex('\t',@HdwString,1),0)= 0 
    BEGIN 
    Select @Success_Desc = 'No Delimeter Defined.' 
    Goto ExitProcedure 
    END 
If IsNull(CharIndex('\r\n',@HdwString,1),0)= 0 
    BEGIN 
    Select @Success_Desc = 'No Row End Defined.' 
    Goto ExitProcedure 
    END 

EXEC sp_FIX_DoubleQuotesMax @HdwString OUTPUT 
/* 
DECLARE @DD1149_Hdw TABLE (
    [Req_Voucher_Number] [varchar](25), 
    [Part_Number] [varchar](50), 
    [Serial_Number] [varchar](50), 
    [Lot_Number] [varchar](50), 
    [Description] [varchar](200), 
    [Federal_Class_Code] [varchar](4), 
    [Item_Code_Desc] [varchar](50), 
    [Unit_Price] [money] NOT NULL, 
    [Unit_Of_Issue] [varchar](20) NOT NULL, 
    [Qty] [decimal](7, 2) NOT NULL 
) 
*/ 
Select @StartLoc = 1, 
     @SLen  = Len(@HdwString), 
     [email protected]  = CharIndex('\r\n',@HdwString,1), 
     @TLoc  = CharIndex('\t',@HdwString,1) 

BEGIN TRANSACTION 

Looper: 
--End Of File? 
IF @TLoc = 0 
    BEGIN 
    --Select 'This is the stub where the parsed date would then be pushed to the PTS_DD1149_Hardware table.' 
    goto ProcessTransaction 
    --Add Records To Hardware Table 
/* 
    IF @@ERROR != 0 
     BEGIN 
     ROLLBACK TRANSACTION 
     Select @Success_Desc = 'There was a problem adding the hardware. No records were added.' 
     END 
    ELSE 
     BEGIN 
     COMMIT TRANSACTION 
     Select @Success_Desc = 'There was a problem adding the hardware. No records were added.' 
     END 
    Goto ExitProcedure 
*/ 
    END 

ELSE 
    BEGIN 
    --ReqVoucher# 
    Select @V = Substring(@HdwString,@StartLoc,@[email protected]) 
    Select @StartLoc = @TLoc + 2 
    --Part# 
    Select @TLoc = CharIndex('\t',@HdwString,@TLoc+1) 
    Select @P = Substring(@HdwString,@StartLoc,@[email protected]) 
    Select @StartLoc = @TLoc + 2 
    --Ser# 
    Select @TLoc = CharIndex('\t',@HdwString,@TLoc+1) 
    Select @S = Substring(@HdwString,@StartLoc,@[email protected]) 
    Select @StartLoc = @TLoc + 2 
    --Lot# 
    Select @TLoc = CharIndex('\t',@HdwString,@TLoc+1) 
    Select @L = Substring(@HdwString,@StartLoc,@[email protected]) 
    Select @StartLoc = @TLoc + 2 
    --Desc 
    Select @TLoc = CharIndex('\t',@HdwString,@TLoc+1) 
    Select @D = Substring(@HdwString,@StartLoc,@[email protected]) 
    Select @StartLoc = @TLoc + 2 
    --Fed Code 
    Select @TLoc = CharIndex('\t',@HdwString,@TLoc+1) 
    Select @F = Substring(@HdwString,@StartLoc,@[email protected]) 
    Select @StartLoc = @TLoc + 2 
    --Item Code 
    Select @TLoc = CharIndex('\t',@HdwString,@TLoc+1) 
    Select @C = Substring(@HdwString,@StartLoc,@[email protected]) 
    Select @StartLoc = @TLoc + 2 
    --Price 
    Select @TLoc = CharIndex('\t',@HdwString,@TLoc+1) 
    Select @M = Substring(@HdwString,@StartLoc,@[email protected]) 
    Select @StartLoc = @TLoc + 2 
    --UOM 
    Select @TLoc = CharIndex('\t',@HdwString,@TLoc+1) 
    Select @I = Substring(@HdwString,@StartLoc,@[email protected]) 
    Select @StartLoc = @TLoc + 2 
    --Qty 
    Select @TLoc = CharIndex('\r\n',@HdwString,@TLoc+1) 
    Select @Q = Substring(@HdwString,@StartLoc,@[email protected]) 

    --SELECT @V, @P, @S, @L, @D, @F, @C, @M, @I, @Q 

    IF Not Exists(Select * From Unit_Of_Issue Where Unit_Of_Issue = @I) 
     IF Not Exists(Select * From Unit_Of_Issue Where UI_Description = @I) 
      BEGIN 
      ROLLBACK TRANSACTION 
      Goto ExitProcedure 
      END 
     ELSE 
      Select @I = Unit_Of_Issue From Unit_Of_Issue Where UI_Description = @I 

    IF Not Exists(Select * From PTS_Item_Codes Where Item_Code = @C) 
     BEGIN 
     ROLLBACK TRANSACTION 
     Goto ExitProcedure 
     END 
    ELSE 
     Select @Item_Code_ID = Item_Code_ID From PTS_Item_Codes Where Item_Code = @C 

    IF @@ERROR != 0 
     BEGIN 
     ROLLBACK TRANSACTION 
     Goto ExitProcedure 
     END 

    Select @Unit_Price = Convert(Money,@M), @Qty = Convert(decimal(7,2),@Q) 
    IF @@ERROR != 0 
     BEGIN 
     ROLLBACK TRANSACTION 
     Goto ExitProcedure 
     END 

    --Select 5, @V, @P, @S, @L, @D, @F, @M, @Item_Code_ID, @Unit_Price, @Qty, @UID 
    exec @retV = sp_PTS_Action_DD1149_Insert_Hardware_No_RecSet @V, @P, @S, @L, @D, @F, @I, @Item_Code_ID, @Unit_Price, @Qty, @UID 
    IF @retV != 1 
     BEGIN 
     ROLLBACK TRANSACTION 
     Goto ExitProcedure 
     END 
    --Add To Table 
    --INSERT @DD1149_Hdw 
    --SELECT @V, @P, @S, @L, @D, @F, @C, @M, @I, @Q 

    --Testing 
    --Select * from @DD1149_Hdw 

    --Select @V, @P, @S, @L, @D, @F, @C, @M, @I, @Q 

    --Reset Variables 
    Select @StartLoc = @TLoc + 4, 
      [email protected] = CharIndex('\r\n',@HdwString,@TLoc+3), 
      @TLoc  = CharIndex('\t',@HdwString,@TLoc+3), 
      @V   = NULL, 
      @P   = NULL, 
      @S   = NULL, 
      @L   = NULL, 
      @D   = NULL, 
      @F   = NULL, 
      @C   = NULL, 
      @M   = NULL, 
      @I   = NULL, 
      @Q   = NULL, 
      @Unit_Price = NULL, 
      @Qty  = NULL, 
      @retV  = NULL 

    END 

Goto Looper 

ProcessTransaction: 
    COMMIT TRANSACTION 

    Select @Success_Nbr = 1 

ExitProcedure: 

If @Success_Nbr = 0 
    Select Convert(Varchar(7),'Failed') as Success_Desc 
Else 
    Select Convert(Varchar(7),'Success') as Success_Desc 

--Select @Success_Nbr as Success_Nbr 
/* 
Select @Success_Nbr as Success_Nbr, 
     @Success_Desc as Success_Desc, 
     * 
From @DD1149_Hdw 
*/ 
+0

어떻게 실패합니까? 오류가 무엇입니까? – JohnD

+0

LINQ-to-SQL에서 실행하면 오류, 메시지, * anything *이 발생합니까 ?? –

+0

마지막으로 오류를 발견하고 잠시 시간을내어 찾았지 만 Fk 제약과 같이 보입니다. 내 DBML이 다른 것 같아서 시도하려고합니다. –

답변

0

Linq에 게으른 될 수 있습니다

여기 내 저장 프로 시저입니다. 노력하고있는 순서대로 인서트가 일어나고 있는지 확실히 확신하고 있습니까? 외래 키 오류가 있다고 생각하면 내 추측은 부정이됩니다.

관련 문제