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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:54:07+00:00 2026-05-19T21:54:07+00:00

I have a class which uses both ADO.NET and LINQ to access a pair

  • 0

I have a class which uses both ADO.NET and LINQ to access a pair of databases on one server. The tables in the DBs are not extensive and so the entity objects are fairly light. I have written the code as best as I, using experience and net articles of course. For example…

http://dotnetperls.com/sqldataadapter
http://www.velocityreviews.com/forums/t71781-set-maximum-pool-size-in-web-config.html
http://msdn.microsoft.com/en-us/library/ms971481#adonetbest_topic5

The server which is running my code is only running my code and is not the same server as the db host. From looking at the connections going to the DB server from the my .NET app server (it’s a Windows Service, but I don’t want to dwell on that as it seem immaterial right now) the number of connections is around 200, but it should certainly be less than that; It should be around 10 as I have set the Max Pool Size to 10 in the appSettings.config.

Could anyone take a look at my connection code and tell me if I’m doing something which would cause the connections to shoot up, please?

Here is my LINQ DB context creation:

private const string ConnectionKey = "SQL2";
protected static string ConnectionString
{
    get
    {
        return _connectionString = (_connectionString == null) ? ConfigurationManager.ConnectionStrings[ConnectionKey].ConnectionString : _connectionString;
    }
}
private static string _connectionString = null;

protected static PricingDBDataContext ContextDB
{
    get
    {
        if (_context == null)
        {
            _context = new PricingDBDataContext(ConnectionString);
        }

        return _context;
    }
}
private static PricingDBDataContext _context = null;

Here is the ADO.NET side of things:

protected DataSet GetDataSet(bool isSproc, string cmdStr, params object[] args)
{
    using (SqlConnection conn = new SqlConnection(ConnectionString))
    {
        using (SqlCommand cmd = new SqlCommand(cmdStr, conn))
        {
            cmd.CommandType = isSproc ? CommandType.StoredProcedure : CommandType.Text;
            for (int index = 0; index < args.Length; index += 2)
                cmd.Parameters.AddWithValue(args[index].ToString(), args[index + 1]);
            conn.Open();
            DataSet set = FillSet(cmd);
            conn.Close();
            return set;
        }
    }
}

private DataSet FillSet(SqlCommand cmd)
{
    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
    DataSet set = new DataSet();
    adapter.Fill(set);
    return set;
}

Thanks,

Matt.

  • 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-19T21:54:09+00:00Added an answer on May 19, 2026 at 9:54 pm

    As a general rule, if you are doing anything explicit with the connection pool, you are probably doing it wrong. The default settings have served me well since the early days of .Net

    Here are some things to keep in mind:

    • ADO will pool connections that have exactly the same connection string
    • Most ado.net objects implement IDisposable and should be disposed of either explicitly or in a using block. This includes connections, commands, datasets and data readers
    • Linq 2 SQL and EF data contexts also implement IDisposable and should be disposed
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class which uses BinaryReader internally and implements IDisposable. class DisposableClass
I have some logic, which defines and uses some user-defined types, like these: class
I have a class which implements UserControl. In .NET 2005, a Dispose method is
I have several files with code testing code (which uses a unittest class). Later
I have a class which uses a method in user32.dll: [System.Runtime.InteropServices.DllImport(user32.dll)] private static extern
I have an application which uses two methods of an API. Both these methods
I have a class which I'm serialising to send over a unix socket and
I have a class which is marked with a custom attribute, like this: public
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
I have a class which looks something like this: public class Test { private

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.