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 964559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:50:55+00:00 2026-05-16T01:50:55+00:00

I did a simple test to understand how transactions work in .net Sample code

  • 0

I did a simple test to understand how transactions work in .net

Sample code on which my transaction test was done is

_sqlHelper = new SqlHelper(true);
try
{
    _sqlHelper.ExecuteNonQuery(SpName.sp_UpdateRoomStatus.ToString()
        , Parameters.SqlParam<int?>("DepartmentId", this.DepartmentId, SqlDbType.Int)
        );

    _sqlHelper.ExecuteNonQuery(SpName.sp_UpdateRoomStatus.ToString()
        , Parameters.SqlParam<int?>("DepartmentId", this.DepartmentId, SqlDbType.Int)
        );

    _sqlHelper.CommitTransaction();
}
catch (SqlHelperException ex)
{
    _sqlHelper.RollBackTransaction();
}

Description about the test

When I writes new SqlHelper(true); a new transaction starts internally and connection has been created and opened to database.

_sqlHelper.ExecuteNonQuery(SpName.sp_UpdateRoomStatus.ToString()
    , Parameters.SqlParam<int?>("DepartmentId", this.DepartmentId, SqlDbType.Int)
    );

Now above function executes my procedure and do changes in a database.

I wrote same function call twice to execute procedure two times. This procedure do insertion in database. This procedure contains 3 insert queries in 3 different tables.
Now I marked breakpoint on both function calls.

As soon as control comes on 1st breakpoint I simply lets its processing do which means 1st procedure has done insertion.

Now I unplugged my LAN wire since DB was on remote system. Which means connection lost. Hence transaction to be rolledback.

Now When I verified database after the whole process completed. I found data to be in consistent state hence proving that transaction is working.

I am confused at this moment that where did an actual insertion took place from 1st procedure call, since procedure executed successfully. How sql server get notified that transaction was going on and rollback has to be taken place.

It seems as if connection was established to database notifying that connection contains transaction and should get rolled back if connection gets lost.

Hence also stating that Changes made are maintained at Database rather than .net environment.

  • 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-16T01:50:56+00:00Added an answer on May 16, 2026 at 1:50 am

    The database knows that the connection and the changes should be in a transaction – the actual changes and original data are stored in the database transaction log. When the transaction isn’t properly committed and the connection is lost, the database automatically rolls back the transaction.

    Basically, in SqlTransactions (not distributed) .Net does nothing clever, it is all handled by the database.

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

Sidebar

Related Questions

I did two sample applications in ios.Both applications i have done using storyboard.Then after
I did simple test and it seems that Java conversions of String to bytes[]
I did try a very simple test to display a row when i click
I have 2 classes: FirstDeep.cs SecondDeep.cs I did simple code for example: class FirstDeep
I have a very simple test case I am using to try to understand
I've created a very simple test Document based application with Core Data. I did
I was playing around with recursion and did this simple function. I was assuming
Perhaps a simple to be answered question, but I did not find a satisfying
What I'm trying to do seems very simple, but I did not yet find
Ok I know this is simple, in fact damn simple, I did this in

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.