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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:22:00+00:00 2026-06-15T19:22:00+00:00

When using ado.net, should I worry about opening and closing too many connections? For

  • 0

When using ado.net, should I worry about opening and closing too many connections?

For example, say I have an MVC controller method that calls 3 separate repositories to fill all the needed objects.

 public ActionResult()
 {
      var codesRepository = new CodesRepository();
      viewModel.codes = codesRepository.GetCodesByName("D");

      var employeeRepository = new EmployeeRepository();
      viewModel.employees = employeeRepository.GetByName("Thomas");

      var companyRepository = new CompanyRepository();
      viewModel.company = companyRepository.GetById(20);

      //.... rest of code
 }

In each GetBy method above, I am opening and closing a connection.

using(var connection = DbFactory.GetConnection('SQLBase') 
{
    // code to fill the objects.
}

Do I need to worry about this approach being that I am opening and disposing a connection for each method called? It seems to me that the same connection should be used for all 3?

I’ve read about connection pooling a bit. Is that a database specific feature, or a feature in ado.net?

  • 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-06-15T19:22:01+00:00Added an answer on June 15, 2026 at 7:22 pm

    Yes, you should – mostly because your design is an anti pattern. While the performance impact is low on read, you totally destroy either transactional integrity OR performance on the write / update side.

    Point is – in order to make updates across multiple repositoies then you need either DTC (slow), or make it repository by repository, which has no transactional integrity.

    Yo also are terribly slow for any select operation that cross references entities. And you ahve a maintenance nightmare.

    companyRepository.GetById(20);

    Should be

    repository.Element<Company>.Where (x => x.id=20);

    This approach would allow you to:

    • Use one repository for everything.
    • Use Company flexible, including join operation and subselects
    • Use one repository with one connection for all updates in a transaction without DTC.

    Right now your problem is not so much the opening, but the updates and the transaction.

    This is an / the approach that is used by Entity Framework etc. – if you want performance, raw, you can use BlToolkit.

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

Sidebar

Related Questions

I am trying to develop an application using ADO.NET. I have two tables in
I have been using ADO.NET in favor of LINQ to SQL (or Entities) up
Scenario I am playing MVC NerdDinner project and using ado.net entity data model instead
I'm using ASP.NET MVC 3 and my repositories are using ADO.NET with stored procedures
I am developing an ASP.NET MVC 3 application using C# and Razor. I have
I have a vb.net app using plain old ado.net to run a s'proc on
I'm using ADO.NET EF in an MVC application. I'm considering putting the ObjectContext inside
I am using ADO.NET, I have created DAL and BAL, structure is as follows
I am using ADO.Net entity framework with asp.net mvc3. I have a model which
how can I by using Ado.net rename existing column in a table and changing

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.