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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:32:51+00:00 2026-05-11T15:32:51+00:00

Suppose I am doing the following: using (OracleConnection conn = new OracleConnection(connStr)) { OracleTransaction

  • 0

Suppose I am doing the following:

using (OracleConnection conn = new OracleConnection(connStr)) {     OracleTransaction trans = conn.BeginTransaction();     OracleCommand command = new OracleCommand(cmdTxt, conn, trans);     // this statement is executed in a transaction context:     command.ExecuteNonQuery(); } // the using statement will dispose and thus close the connection. // a rollback is done implicitly 

Although I did not executed transaction.Rollback(), my tests showed that a rollback is done implicitly.

My question is: Will this code leak connections or anything else?

Edit1: I am the System.Data.OracleClient namespace.

Edit2: This is a contrieved example code. The more realistic scenario is when within the using statement an exception occures and the Commit() statement is not executed yet.

Edit3: From the answer I think that this is favorable:

using (OracleConnection conn = new OracleConnection(connStr)) using (OracleTransaction trans = conn.BeginTransaction()) using (OracleCommand command = new OracleCommand(cmdTxt, conn, trans)) {     command.ExecuteNonQuery();     trans.Commit(); } 

Should cleanly dispose anything and make clear what is happening.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T15:32:52+00:00Added an answer on May 11, 2026 at 3:32 pm

    It will not leak. The using clause guarantees that the OracleConnection will be disposed, regardless of whether the command completes successfully or fails with an exception, and it will take the transaction with it.

    But since OracleTransaction is IDisposable, it would probably be good form to put a using clause around the transaction as well, e.g.

    using (OracleTransaction trans = conn.BeginTransaction()) {   // ...   trans.Commit(); } 

    This will make it clearer to readers of the code that the transaction is being cleaned up; in particular, it may become important if a subsequent enhancement performs multiple transactions on the same connection.

    Also, as per John’s comment below, you should put a using statement around the OracleCommand, so that it can be cleaned up promptly.

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

Sidebar

Related Questions

The following code is suppose to be doing this : - Displaying a string
I'm trying to learn about shift-reduce parsing. Suppose we have the following grammar, using
Suppose I want perform a simulation using the following function : fn1 <- function(N)
Hi guys I have the following VHDL which isn't doing what it suppose to
I am doing a P/Invoke, and I am using the following method [DllImport(Authz.dll, SetLastError
Let's suppose I have the following regex: -(\d+)- and I want to replace, using
I need to obtain coordinates for my application...I am doing this by using LocationManager
I'm doing something stupid, I suppose. I swear I've done this before without issues
Having searched StackOverflow, and Google I think what I'm doing is suppose to be
Suppose I have a script: my_script.sh Instead of doing ./my_script.sh I want to do

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.