#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Question Using statement and transactions


    Hi,

    Please let me know if the bellow code is correct.
    Is the connection closed and disposed and transaction rolled back and closed and disposed in case of exception?
    Any other suggestions are welcome.

    Thank you,
    Adrya



    Code:
     using (FbConnection c = new FbConnection(m_connection))
              {
                c.Open();
    
                using (FbTransaction trans = c.BeginTransaction())
                {
                  using (FbCommand cmd = new FbCommand("DELETE_MESSAGES_QUEUE", c, trans))
    
                  {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add("INQUEUENAME", queueName);
      
    
                    cmd.ExecuteNonQuery();
                  }
                  using (FbCommand cmd = new FbCommand("DELETE_QUEUE", c, trans))
    
                  {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add("INQUEUENAME", queueName);
      
    
                    cmd.ExecuteNonQuery();
                  }
                  trans.Commit();
      
                }
                
      
              }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,054
    Rep Power
    383
    You might like to include the language you are using.
    In Java you should close connections once you are done with them.

IMN logo majestic logo threadwatch logo seochat tools logo