Database locking

Posted on 2006-03-30
Last Modified: 2010-04-23
Hi Guys

I have a big string which contains a whole lot of batch queries and I was wondering how to lock the database or even better specific tables then perform the batch queries and then unlock either the tables or the database. I am running on sql server 2006. Basic code is below not exact but just to show how I am currently running the queries.

Dim DatabaseConn As SqlConnection = New SqlConnection("Server=sdf;UID=sdg;PWD=dfb;DATABASE=dfb")
Dim SqlQuery As SqlCommand
SqlQuery = New SqlCommand(QueryString, DatabaseConn)
Question by:peter58
    LVL 8

    Expert Comment


    I assume you meant SQL Server 2005, and not 2006!

    Not too sure if there's any new features for this, but I believe what you're looking for is called a "locking hint" (refer to SQL Server Books Online for more information).

    So your INSERT/UPDATE/DELTE, would look something like this:

     (col1, col2, colN)
     (val1, val2, valN)

    Hope this helps.

    Best Regards,

    LVL 4

    Author Comment

    Is there no way to lock it before and after all the batch queries as I want to update or insert them all before anyone can access them.
    LVL 6

    Accepted Solution

    I think utilizing a transaction would give you what you are looking for.
    LVL 6

    Expert Comment


    I believe the default isolation level in a transaction is 'serializable' which means: "A range lock is placed on the DataSet, preventing other users from updating or inserting rows into the dataset until the transaction is complete."  


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now