Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 516925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:46:53+00:00 2026-05-13T07:46:53+00:00

The code ALTER PROCEDURE [dbo].[spSocial.QuestionsAddNew] @IdUser int, @IdQuestionCategory int, @Title int, @Body int, @CreatedDate

  • 0

The code

ALTER PROCEDURE [dbo].[spSocial.QuestionsAddNew]
    @IdUser             int,
    @IdQuestionCategory     int,
    @Title                  int,
    @Body                   int,
    @CreatedDate            int,
    @ActivityDate           int,
    @VotesCount             int,
    @AnswersCount           int,
    @ViewedCount            int
AS
BEGIN
    SET NOCOUNT ON;

    insert into
        tblSocialQuestions
        (IdUser, IdQuestionCategory, Title, Body, CreatedDate, ActivityDate, VotesCount, AnswersCount, ViewedCount)
    values
        (@IdUser, @IdQuestionCategory, @Title, @Body, @CreatedDate, @ActivityDate, @VotesCount, @AnswersCount, @ViewedCount)

    select @@IDENTITY

    exec [spSocial.Questions2Users] @IdUser, 'AskedCount', 1

END

From what I understand

The @@identity function returns the
last identity created in the same
session.

The session is the database
connection. The scope is the current
query or the current stored procedure.

If the session is the current database connection, isn’t there a problem in using @@Identity in a multithreaded environment as ASP .NET users requestes ?

If 10 users adds a new question at the same time, and [spSocial.QuestionsAddNew]
stored procedure is executed in multithreaded environment with the same SqlConnection, isn’t there a problem in using @@Identity ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:46:54+00:00Added an answer on May 13, 2026 at 7:46 am

    One ADO.NET connection can only execute one command at a time. In almost all cases, different ASP.NET threads will have different connections, which they keep around for the duration of a single page request. But even if the ASP.NET threads somehow shared a connection, they’d have to use the connection in such a way that only one thread can use a it at a time, or ADO.NET would raise an error.

    So no, there’s no danger in using @@IDENTITY in a multithreaded ASP.NET environment.

    By the way, it’s good practice not to use @@IDENTITY; use SCOPE_IDENTITY() instead. The latter also works after someone adds a trigger on the table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ALTER PROCEDURE [dbo].[GetTimeSheetsAttendance] @WhereClause varchar AS EXEC ('Select vwEmployeeList.ID,vwEmployeeList.Code, tbGNClient.FName + '' '' +
I have a stored procedure with the following code. alter PROCEDURE [dbo].[usp_Product_GetProductByCategoryID] @CategoryID uniqueidentifier,
The code is as follows: ALTER PROCEDURE dbo.pdpd_DynamicCall @SQLString varchar(4096) = null AS Begin
I have a procedure and the code looks like this: ALTER PROCEDURE [dbo].[usp_Gen_Proc] (@ID
My stored procedure is: ALTER PROCEDURE [dbo].[Insert_QuickLabDump] @Specimen_ID [varchar](50), @Client_Key int, @Outcome [varchar](50), @Medications
Here's my SQL Server stored procedure : ALTER PROCEDURE [dbo].[SearchUser] (@Text NVARCHAR(100), @TotalRows INT
I Create this stored procedure ALTER PROCEDURE [dbo].[Stock_Master_Sp] @common nvarchar(1)='', @PK_ID int=0, @FK_StoneCategory_Master int=0,
I am using this code to alter the title of an image. Basically it
ALTER PROCEDURE dbo.StoredProcedure8 @emp_code bigint, @co_id bigint, @p decimal(8,2) output AS SELECT @p =
I have the following stored procedure ALTER PROCEDURE [dbo].Test AS BEGIN CREATE TABLE ##table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.