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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:49:53+00:00 2026-05-10T17:49:53+00:00

Assume the following code: using (SqlConnection conn = new SqlConnection(connectionString)) { … using (SqlCommand

  • 0

Assume the following code:

using (SqlConnection conn = new SqlConnection(connectionString)) {    ...    using (SqlCommand comm = new SqlCommand(...))    {       .. do stuff ..       if(condition) Response.Redirect('somepage.aspx');     } } 

Will the Response.Redirect() exit from the using blocks cause it to dispose all connections?

Or, alternatively, is there any way to exit a using block that won’t cause disposal?

EDIT: I don’t want to exit without disposal. I want to be aware of any pitfalls that would cause it not to work. — Barring crashes of course, but then I’m pretty sure all objects are disposed –the hard way– in that situation

I’ve accepted an answer, which essentially says ‘I don’t know’ but it’s a very well researched ‘I don’t know’

For the mean time, I’m going to assume that Response.Redirect aborts the using statement and code with that in mind. — Until proven otherwise.

  • 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. 2026-05-10T17:49:54+00:00Added an answer on May 10, 2026 at 5:49 pm

    From http://msdn.microsoft.com/en-us/library/aa973248.aspx

    Calling Response.Redirect WILL NOT execute the finally block. Therefore, before any redirection or transfer of processing can occur, you must dispose of the objects.

    Yes, it does not directly address the Using statement, but it is a common enough programming practice to be aware of. Also, that article refers to SharePoint, but as SP is built on ASP.NET 2.0, I think it is still relevant.

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

Sidebar

Ask A Question

Stats

  • Questions 60k
  • Answers 60k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer echo php_uname('n'); see http://php.net/manual/en/function.php-uname.php May 11, 2026 at 9:29 am
  • added an answer Can't you make the trunk read-only for those specific people,… May 11, 2026 at 9:29 am
  • added an answer It looks like this package is not installed by default.… May 11, 2026 at 9:29 am

Related Questions

Assume the following code: using (SqlConnection conn = new SqlConnection(connectionString)) { ... using (SqlCommand
Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
Assume the following class: public class MyEnum: IEnumerator { private List<SomeObject> _myList = new
Assume the following: models.py class Entry(models.Model): title = models.CharField(max_length=50) slug = models.CharField(max_length=50, unique=True) body
Assume the following type definitions: public interface IFoo<T> : IBar<T> {} public class Foo<T>
Assume a table with the following columns: pri_id , item_id , comment , date
Assume you are doing something like the following List<string> myitems = new List<string> {
Assume your .NET-based development team is already using the following set of tools in
When writing GUIs, I've frequently come over the following problem: Assume you have a
This is an Eclipse question, and you can assume the Java package for all

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.