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

  • Home
  • SEARCH
  • 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 717127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:22:37+00:00 2026-05-14T05:22:37+00:00

I have an audit record table that I am writing to. I am connecting

  • 0

I have an audit record table that I am writing to. I am connecting to MyDb, which has a stored procedure called ‘CreateAudit’, which is a passthrough stored procedure to another database on the same machine called MyOther DB with a stored procedure called ‘CreatedAudit’ as well.

In other words in MyDB I have CreateAudit, which does the following EXEC dbo.MyOtherDB.CreateAudit.

I call the MyDb CreateAudit stored procedure from my application, using subsonic as the DAL. The first time I call it, I call it with the following (pseudocode):

            int openStatus, closeStatus = 0;
            openStatus = Convert.ToInt32(SPs.LogAccess(userId, "OPENED"));
            closeStatus = Convert.ToInt32(SPs.LogAccess(userId, "CLOSED"));

This is simplified, but this is what LogAccess calls:

 ALTER procedure [dbo].[LogAccess]
      @UserID           uniqueid,
      @Action           varchar(10),          
      @Status           integer output

 as

 DECLARE @mStatus INT

 EXEC [MyOtherDb].[dbo].[LogAccess]
      @UserID = @UserID,
      @Action = @Action,        
      @Status = @mStatus OUTPUT


 select @mStatus

In my second stored procedure it is supposed to mark the record that was created by the CreateAudit(recordId, “Opened”) with a status of closed.

This works great if I run them independently of one another, or even if I paste them into query analyzer. However when they execute from the application, the record is not marked as “Closed”.

When I run SQL profiler I see that both queries ran, and if I copy the queries out and run them from query analyzer the record gets marked as closed 100% of the time!

When I run it from the application, about once every 20 times or so, the record is successfully marked closed – the other 19 times nothing happens, but I do not get an error!

Is it possible for the .NET app to skip over the ouput from the first stored procedure and start executing the second stored procedure before the record in the first is created?

When I add a “WAITFOR DELAY ’00:00:00:003′” to the top of my stored procedure, the record is also closed 100% of the time.

My head is spinning, any ideas why this is happening!

Thanks for any responses, very interested in hearing how this can happen.

  • 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-14T05:22:37+00:00Added an answer on May 14, 2026 at 5:22 am

    In your 1st stored proc, try having the EXEC statement wait for a return value from the 2nd stored proc. My suspicion is that your first SP is firing off the 2nd stored proc and then immediately returning control to your .NET code, which is leading to the above commenter’s concurrency issue. (That is to say, the 2nd SP hasn’t finished running yet by the time your next DB call is made!)

    SP1: EXEC @retval = SP2 ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called 'Audit' in SQL Server 2005 like this: Name |
I have a table with a timestamp column that records when the record is
Say I have some data stored in an audit table, where triggers on the
Suppose you have the following... An ASP.NET web application that calls a stored procedure
I have an audit table in my SQL Server 2008 database which contains the
I have an audit table in SQL server. It is to record an entry
We have a simple table (an audit log) that our (3rd-party) product fills with
I have a table called Staff and a table called Supervisors. Staff has StaffID
I have a table of records, which has a self-relationship. Additionally - to make
We have a trigger that creates audit records for a table and joins the

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.