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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:20:12+00:00 2026-05-11T05:20:12+00:00

I want to use this pattern: SqlCommand com = new SqlCommand(sql, con); com.CommandType =

  • 0

I want to use this pattern:

SqlCommand com = new SqlCommand(sql, con); com.CommandType = CommandType.StoredProcedure;//um com.CommandTimeout = 120; //com.Connection = con;  //EDIT: per suggestions below  SqlParameter par; par = new SqlParameter('@id', SqlDbType.Int); par.Direction = ParameterDirection.Input;  com.Parameters.Add(par);  HttpContext.Current.Cache['mycommand'] = com; 

Obviously I don’t want to run into odd problems like person A retrieving this from the cache, updating param1, person 2 getting it from the cache and updating param2 and each user running the command with a blend of the two.

And cloning the command taken out of the cache is likely more expensive that creating a new one from scratch.

How thread safe is the ASP.NET Cache? Am I missing any other potential pitfalls? Would this technique work for parameterless commands despite threading issues?

Clarefication: If I want to metaphorically shoot myself in the foot, how do I aim? Is there a way to lock access to objects in the cache so that access is serialized?

  • 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. 2026-05-11T05:20:12+00:00Added an answer on May 11, 2026 at 5:20 am

    I should have asked how to lock an item in ASP.NET cache, instead of saying what I was intending to put in the cache.

    lock(Cache)   {     // do something with cache that otherwise wouldn't be threadsafe   } 

    Reference: http://www.codeguru.com/csharp/.net/net_asp/article.php/c5363

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

Sidebar

Ask A Question

Stats

  • Questions 153k
  • Answers 153k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You won't get a leak, surprisingly enough. See : Memory… May 12, 2026 at 10:15 am
  • Editorial Team
    Editorial Team added an answer Have you tried: [button setTitleShadowColor:[UIColor blueColor] forState:UIControlStateNormal]; May 12, 2026 at 10:15 am
  • Editorial Team
    Editorial Team added an answer Trivial with jQuery $('#div1').insertAfter('#div3'); $('#div3').insertBefore('#div2'); If you want to do… May 12, 2026 at 10:15 am

Related Questions

Considering the following sample code: // delivery strategies public abstract class DeliveryStrategy { ...
Whats the best design pattern to use for LINQ and type tables that exist
Linux: I want to list all the files in a directory and within its
I'm trying to figure out a Java regex problem that I'm having. This is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.