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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:30:41+00:00 2026-05-22T23:30:41+00:00

I have a asp.net webmethod which is static and it will do delete operation

  • 0

I have a asp.net webmethod which is static and it will do delete operation of user’s files in the DB.
The file_name is sent through jQuery as input. But the for DB connection, I need to use a static DBconnection object.

When multiple users delete their own file from UI, the jQuery will hit the same static method, which uses a single Static connection object.
So multiple requests arise at the same time, will this delete only the last(latest request) users file is deleted from the DB? If so how to handle this with jquery-ajax in asp.net.

Please throw some light if i stated something wrong.

[Updated]
Server side code:

  public static void DeleteAttachment(int fileId, string fileLoc)
  {
   SqlDBAccess objDBAccessStat = new SqlDBAccess();
   .......
  }
  • 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-22T23:30:42+00:00Added an answer on May 22, 2026 at 11:30 pm

    Obviously, if you share the DB connection between multiple requests simultaneously there’s not telling what will happen. This is per definition undefined.

    What you need to do is that either isolate the thing (make it non-static) or introduce a lock that will force incoming requests to wait indefinitely (until the operation is available).

    This isn’t particularly hard per se but requires one to be careful as to not introduce a dead lock.

    I recommend though that you don’t make your method static, a non-static method is more isolated and used properly with it’s own connection object won’t be prone to the same concurrency issue.

    The important thing here is that the DB connection isn’t a global shared resource when multiple users hit that method or things will go wrong.

    Just change it to something like this:

    static void WebMethod()
    {
        using (var conn = ProviderFactory.CreateConnection("connection string goes here"))
        {
            conn.Open();
            // Do work here
        }
    }
    

    The neat part about the above is that you won’t be spamming the server with connections simply because the connection pool is enabled by default, assuming that you using the SqlClient database provider. It will however give you a nice isolated scope conn do your your database work in.

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

Sidebar

Related Questions

I have some ASP.NET page and webservice WebMethod() methods that I'd like to add
I have ASP.NET web pages for which I want to build automated tests (using
I have some ASP.NET web services which all share a common helper class they
jQuery 1.3.2, ASP.NET 2.0. Making an AJAX call to a PageMethod (WebMethod) returns the
I have a asp.net web-service which I use from my ASP.NET website. I can
I have an ASP.net web service that I'm using for a web application which
Can anyone help? I have an issue with calling a asp.net webservice from jquery..
We have asp.net mvc 2 site which allows www and without any subdomain. For
I have an ASP .NET Web Forms application that makes use of the 'WebMethod'
I have an asp.net WebMethod that returns an XmlDocument object. I can successfully call

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.