Stored Procedure works manually, but not through C# code RRS feed

  • Question

  • I have a problem in using stored procedure (“AddNewTestResultsHeader”. This will add a new entry to a table called TestResultsHeader). This works fine if I enter the value manually. The same doesn’t work in Code.

    When my C# code executes this stored procedure, the value for new TestResultsID (which is a auto generated primary key) is returned while the entry doesn’t exist in the table.


    I have enclosed the content of the table. The values for TestResultsID between 13-34 are missing because, when this stored procedure is executed through my code, the new Value for TestResultsID is returned, hence exception is not raised. While the entry is not found in table.

    The entries 34, 36 are given manually (executing this stored procedure manually) and data is found in stored procedure too.


    I am not able to figure the bug. Help very critical, please help.



    TestResultsID bigint          (Pimary Key, autoGenerated)
    TestID  int 
    RunBy  smallint 
    RunDate  smalldatetime  (Value specified as current date and time)
    Passed  tinyint                  (Default value given as 0)
    LastPassID bigint 
    TestRunning tinyint 

    Stored Procedure:

    ALTER Procedure AddNewTestResultsHeader
      @TestID   int,
      @RunBy   smallint, 
      @LastPassID  bigint,
      @TestRunning tinyint,
      @TestResultsID bigint  OUTPUT


    INSERT INTO TestResultsHeader
                          (TestID, RunBy, LastPassID, TestRunning)
    VALUES     (@TestID,@RunBy,@LastPassID,@TestRunning)
    SET   @TestResultsID = @@IDENTITY


    • Moved by nobugz Friday, September 4, 2009 4:25 AM not a 64-bit .net q (From:64-Bit .NET Framework Development.)
    Thursday, September 3, 2009 2:05 PM


All replies