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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:50:23+00:00 2026-05-26T10:50:23+00:00

simply put, my sqlservr.exe is memory leaking when ever my service uses it. So

  • 0

simply put, my sqlservr.exe is memory leaking when ever my service uses it. So the question is, Where and why! 🙁

I intialise my connection as nulls. and have a finally clause to ensure they are closed… (ive also tried .dispose on the datareader, but doesnt help).

I’ve tried identifying the problem for over a day. All I can tell is that it is here somewhere.

private Int32 GetCount(String From, String Where)
{

    //Build SQL string from given parameters.
    String sql = "SET dateformat DMY SELECT COUNT(*) as Count FROM " + From + " WHERE " + Where;
    SqlDataReader dataCount = null;
    SqlCommand sqlCommCount = null;
    SqlConnection sqlConCount = null;
    try
    {
        sqlCommCount = new SqlCommand();
        sqlConCount = new SqlConnection();
        sqlCommCount.Connection = sqlConCount;
        sqlConCount.ConnectionString = "connectionstring";
        sqlCommCount.CommandText = sql;
        sqlConCount.Open();

        dataCount = sqlCommCount.ExecuteReader();
        while (dataCount.Read())
        {
            return Convert.ToInt32(dataCount["Count"]);
        }
        return 0;
    }
    finally
    {
        sqlConCount.Close();
        sqlCommCount.Dispose();
        if (dataCount != null)
            dataCount.Close();

    }
}

SOLVED:

  1. There is no leak.

  2. I hate Sqlserver for not telling me it caches memory that isnt in use when connections are madee, so just increases and increases (until it is needed).

  • 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-26T10:50:24+00:00Added an answer on May 26, 2026 at 10:50 am

    Refactor your code with this keyword: using

    Memory occupation is not deterministic, in you sample the effective memory used by the executable will be freed only when Garbage Collection occurs, so you can see memory increase but this could be not an issue, it will be collected sooner or later and memory will return to a proper value.

    After seeing the comment, then the problem seems not to be in your C# code (also if using the using keyword it’s a good idea!), if there is a problem…

    SQL Server will increase memory occupation until it has memory available, it’s designed to work that way. In your sample each time you pass a new where clause it will cache the SQL statement and so memory usage will increase until you have memory available.

    In this case I suggest you to refactor your code to use at least SQL parameters to create the where clause, so the SQL will always remains the same and only the parameters change, this way SQL server will cache only one SQL statement and not thousands. Better yet is to create a stored procedure, but parameters are usually enough.

    Keep also in mind that the way you’re building your SQL statement is really unsafe and could lead to SQL injection attacks, using parameters will fix that too.

    Regards

    Massimo

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

Sidebar

Related Questions

Simply put, I have a table with, among other things, a column for timestamps.
Simply put I want what http://www.reddit.com/ and http://news.ycombinator.com/ have to the left of every
Very simply put: I have a class that consists mostly of static public members,
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
Simply put: I have a database design in my head and I now want
Simply put, I have a string with a prefix msg followed by some numbers
Simply put: I have a table with 2 columns: one is username and other
Simply put, I have a website where you can sign up as a user
I have a new project which simply put, is an attempt to formalize the
Simply put, I have my RSSItem Class and my RSSService class, and a button

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.