Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server 2008 Problem with SCOPE_IDENTITY()
    primarykey
    data
    text
    <p>My code does not update the thread field. It is null. Anyone have any ideas?</p> <pre><code>INSERT INTO [Messages]([Sender], [Receiver], [Job_Number], [Subject], [MessageText], [DateSent]) VALUES(@Sender, @Receiver, @Job_Number, @Subject, @MessageText, @DateSent) SET @ThreadID = SCOPE_IDENTITY() UPDATE [Messages] SET Thread = @ThreadID WHERE MessageID = @ThreadID </code></pre> <p><strong>EDIT:</strong> It seems the UPDATE routine isn't being executed at all. I even added the following code to the end of the sproc, but nothing gets updated.</p> <pre><code>UPDATE Comments SET SomeField = @ThreadID where SCID = 33 </code></pre> <p><strong>EDIT:</strong> </p> <pre><code>/****** Object: Table [dbo].[Messages] Script Date: 04/09/2010 12:08:55 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Messages]( [MessageID] [int] IDENTITY(1,1) NOT NULL, [Sender] [varchar](30) NOT NULL, [Receiver] [varchar](30) NOT NULL, [Job_Number] [varchar](20) NULL, [Subject] [varchar](200) NULL, [MessageText] [varchar](max) NULL, [DateSent] [datetime] NULL, [Thread] [int] NULL, CONSTRAINT [PK_Messages] PRIMARY KEY CLUSTERED ( [MessageID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO ALTER TABLE [dbo].[Messages] ADD CONSTRAINT [DF_Messages_DateSent] DEFAULT (getdate()) FOR [DateSent] GO </code></pre> <p><strong>EDIT:</strong> When I execute the stored procedure from Management Studio, the update works just fine. The problem is in my app when I call it using SQLHelper: </p> <pre><code>SqlHelper.ExecuteNonQuery(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString, "spMessagesInsert", 0, message.Sender, message.Receiver, message.Job_Number, message.Subject, message.MessageText, message.DateSent ); </code></pre> <p><strong>EDIT:</strong> Ultimately, I changed the program code to call the stored procedure using Linq-to-sql instead of using SqlHelper. This seemed to fix the issue. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload