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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:50:38+00:00 2026-06-06T22:50:38+00:00

i am using 3 tier architecture in my winform application so i have static

  • 0

i am using 3 tier architecture in my winform application so i have static class which handle the operation of equipment

 public static class Equipments 
{


    public static void AddEquipment(string name, decimal dimLength)
    {

            DBClassesDataContext db = new DBClassesDataContext();

            Equipment equipment = new Equipment();
            equipment.Name = name;
            equipment.DimLength = dimLength;

            db.Equipments.InsertOnSubmit(equipment);
            db.SubmitChanges();

    }



  public static void UpdateEquipment(int equipmentID, string name, decimal dimLength)
        {
                         DBClassesDataContext db = new DBClassesDataContext();

                Equipment oldEquipment;
                oldEquipment = db.Equipments.Where("EquipmentID = @0",equipmentID).SingleOrDefault();
                oldEquipment.Name = name;
                oldEquipment.DimLength = dimLength;

                db.SubmitChanges();}

so my questions are :

  1. Do i need to create instance of DBClassesDataContext in each method ?
    because when i done global static DBClassesDataContext it didn’t work correctly.
  2. Is there any better way to handle DBClassesDataContext instead to create it each time inside the method (like create new DBClassesDataContext each time i run a method from this class)

Thanks

  • 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-06T22:50:39+00:00Added an answer on June 6, 2026 at 10:50 pm

    Do i need to create instance of DBClassesDataContext in each method?

    You should do, absolutely – just like you should normally create a new SqlConnection each time you want to access the database in non-LINQ code. In general, avoid global state – it’s almost always a bad idea.

    There is any better way to handle DBClassesDataContext instead to create it each time inside the method

    No – that’s exactly the right approach. Why would you try to avoid just creating it each time?

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

Sidebar

Related Questions

I'm creating a web application using asp.net & WCF as 3 tier architecture, which
I'm using a 3-tier architecture for my application. I'm using inline code to call
I have a three-tier Windows Forms DB application in VB.NET. I'm using VS 2005.
I have an application based on 3 tier architecture with postgres database(npgsql) having more
We have a typical multi-tier/layer architecture. Application + WCF Service + Repository/EF4/Database. We are
I have been developing applications that have a three-tier architecture and mostly using MVC
I'm working with an n-Tier application using WinForm and WCF Engine Service (Windows Service)
In one of my projects, I'm using an n-tier architecture DAL (Repository Pattern) <->
For a couple of years, I've been using the three-tier architecture (Presentation, Logic and
I have for some time build n-tier Applications using a database server as the

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.