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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:39:33+00:00 2026-05-25T15:39:33+00:00

I have a vb.net web app and I am passing a SQL connection and

  • 0

I have a vb.net web app and I am passing a SQL connection and a transaction to a method which writes a single record to the database.

I would like to start and commit a transaction for each record that is written but using the same sql connection until the loop is done.

One method I saw was utilizing a using statement but it didn’t work for me.it runs the first time and gives an error on the second that the transaction has already been commited

Using sqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
  sqlConnection.Open()
  Using transaction = sqlConnection.BeginTransaction(IsolationLevel.ReadCommitted)

      For Each user In users
         Try
            myDataWriteMethod(user, conn, tr)

         Catch ex As Exception
            tranaction.rollback()
         End Try
         transaction.commit()
      Next 
    End Using
End Using  
  • 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-25T15:39:33+00:00Added an answer on May 25, 2026 at 3:39 pm

    It looks as if you are committing or rolling back the transaction at each step of the for loop. You probably need to either (1) begin a new transaction for each user, e.g.,

    Using sqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
      sqlConnection.Open()
      For Each user In users
          Using transaction = sqlConnection.BeginTransaction(IsolationLevel.ReadCommitted)
          ...
    

    or (2) only commit or rollback the transaction at the end, e.g.

    Using sqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
      sqlConnection.Open()
      Using transaction = sqlConnection.BeginTransaction(IsolationLevel.ReadCommitted)
    
          Try
              For Each user In users
                  myDataWriteMethod(user, conn, tr)
              Next
          Catch ex As Exception
              tranaction.rollback()
          End Try
    
          transaction.commit()
      End Using
    End Using
    

    Note that I’m not a VB.NET programmer so my syntax may be wrong.

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

Sidebar

Related Questions

I have an ASP.NET web app where I use an ado sql connection to
I have an asp.net web app which holds its data in an sql server
Have an ASP.net web app which works fine for a few days, but then
I have a SQL query in my ASP.net web app that looks like this:
I have a SQL Server 2000, C# & ASP.net web app. We want to
I have a Windows (not Web) NET 1.1 app which can accept the settings
I have an ASP.NET web app which is small yet has a fair amount
I have an Asp.Net web app which users include a script tag in their
I have an ASP.NET web app which is growing. It is done in traditional
Greetings, I have a large .Net web app which runs on a farm of

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.