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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:27:11+00:00 2026-06-02T20:27:11+00:00

Is there any tools within Linq that would permit to lock a database or

  • 0

Is there any tools within Linq that would permit to lock a database or a set of tables explicitely ? I am working with a a few different databases and I am looking for something transparent. At my surprise, I couldn’t find much on the topic apart from topics dealing with how Linq deals with concurrency issues, which is out of my scope.

Alternatively, any other simple way for locking databases would be interesting to me (MsSql, Sybase in particular)

  • 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-02T20:27:13+00:00Added an answer on June 2, 2026 at 8:27 pm

    Locking databases is well outside of the scope of LINQ; the only locking aspects that are relevant would be the locking semantics a particular provider used to provide concurrency guarantees. You’ll need to go to something lower level if you want explicit locks beyond the ones that would be automatically applied by the transaction processing.

    To execute arbitrary SQL commands through Entity Framework, you can use the ExecuteStoreCommand method on the database context, which just takes a SQL string to execute. If for some reason you’re using the older LINQ2SQL provider, it has a similar ExecuteCommand method for accomplishing the same goal.

    There really isn’t such a thing as a “database lock” (at least it database terminology), in the sense that the entire database can be quickly switched into an exclusive-access mode and back out. For Sybase (and MSSQL), someone with the proper rights can accomplish this by setting the “single user” option:

    sp_dboption mydatabase, "single user", true
    

    This is nowhere near as “simple” as just taking a lock: it means that only one person at a time will be allowed to connect to the database, so you need to make sure that you’re connected at the time you set the option on, and that no one else is connected (they will be kicked off without warning), and that you set the option back off when you’re done.

    In MySql, as far as I’m aware, there’s no way to accomplish this short of changing everyone’s permissions on the target database.

    Locking individual tables is a bit easier, as most database servers have SQL-like syntax for doing so. In MySql you use the LOCK TABLES command, with a READ or WRITE lock, though I strongly encourage you to read the linked page because MySql locking works (IMO) somewhat strangely. Sybase similarly has a LOCK TABLE command, in this case called SHARED and EXCLUSIVE.

    You are expected to lock tables within the context of a transaction, so you’ll probably want to wrap your code up in a TransactionScope before you do any locking.

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

Sidebar

Related Questions

Are there any tools that can look at a database, and generate the basic
Are there any tools/ ant tasks that could be integrated into the ant build
Are there any tools available that will let me rebase in git style an
Are there any tools/libraries on Windows that can help me tarck down the culprit?
Are there any tools that display output of a line of code such as
Are there any tools available, or perhaps utility methods within NHibernate, which may help
Are there any tools to assist with the internationalization of Strings within JSP files?
Are there any tools for UI screen design for mobile devices or Is most
Is there any tools or utilities to help in debugging ASP.NET MVC Routing issues?
Are there any tools for performing static analysis of Scala code, similar to FindBugs

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.