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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:36:29+00:00 2026-05-26T11:36:29+00:00

I have and asp.net mvc 3 web site. When running it on local VS

  • 0

I have and asp.net mvc 3 web site. When running it on local VS web server or IIS express it`s ok. But when running it on IIS (IIS 7.5 Windows 2008 R2) it seems like memory leak as memory usage is growing all the time. Any ideas?

One more update: there`s such a code in the app:

SqlConnection conn = new SqlConnection { //creating connection here };
conn.Open();
SqlCommand command = conn.CreateCommand();

try
{
    var reader = command.ExecuteReader();
    while (reader.Read())
    {
       //read the data
    }
}
finally
{
   conn.Close();
}

Maybe there should be something like reader.Dispose? Can it be the cause of memory leak?


UPDATE: for some reason gc.Collect fixes the issue. But it`s not hte way out as calling gc.collect all the way is a bad idea.

  • 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-26T11:36:30+00:00Added an answer on May 26, 2026 at 11:36 am

    well best practice here would be to use brackets, this is a great feature of c#. when you use the “using” keyword with a bracket, it would dispose the used object automatically, when running out of the bracket scope. here’s an example;

    // SqlConnection implements IDisposable, will be disposed after bracket is closed
    using(SqlConnection conn = new SqlConnection())
    {
          conn.Open();
          // SqlCommand implements IDisposable, will be disposed after bracket is closed
          using(SqlCommand command = conn.CreateCommand())
          {
             // DataReader implements IDisposable, will be disposed after bracket is closed
             using(var reader = command.ExecuteReader())
             {
                while (reader.Read())
                { 
                  // read here.
                }
             }
          }
    }
    

    Here’s also the microsoft link that says “The connection is automatically closed at the end of the using block.” http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.close%28v=VS.85%29.aspx

    I hope it helps.

    • 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 MVC 3 web site that uses Windows Authentication running under
I have an IIS7.5 web-site, on Windows Server 2008, with an ASP.NET MVC2 web-site
I have an asp.net mvc app running on a local iis website that is
I have an ASP.NET MVC web application running in IIS as a subweb; let's
We have an internal ASP.NET Webforms application running on a Windows 2008/IIS7 server which
I have an ASP.NET 4.0 MVC web application running on IIS 6.0 with a
I have an ASP.NET MVC web site. I have many actions which require authentication
i have a hosted web site and i have an asp.net mvc site. The
I have an asp.net (mvc) web site. As the part of the functions I
I have Elmah up and running in my ASP.NET MVC site and I would

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.