question about rebuild index with smo

Posted on 2014-03-13
Last Modified: 2014-03-24

The following error is returned when I execute the script if page level locking is disabled

ERROR - Microsoft.SqlServer.Management.Smo.FailedOperationException: Reorganize failed for Index 'idx_tms_login_log_date'.  ---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: The index "idx_log_date" on table "login" cannot be reorganized because page level locking is disabled.

I have modified the script like :

if ($Average_Fragmentation -gt 40.00 -and $Index.IsDisabled -eq $false -and $Index.IsPageLockDisallowed -eq $false)

                  Try {  
                  $A = "REBUILD INDEX"
                  LogIt $SQLREBUILD_LOG " $A of $db $table $index completed" $true  
                  Catch [exception] {                
                  LogIt  $SQLREBUILD_LOG ("ERROR - " + $_.Exception) $true                
                  LogIt  $SQLREBUILD_LOG "" $false                

But no index is rebuild now even if page level locking is not disabled

Why ?

Question by:bibi92
  • 3
  • 3
LVL 26

Expert Comment

ID: 39927747
Maybe this helps:

You can also use an alter statement for the index:
ALTER INDEX index_name ON table_name SET (ALLOW_PAGE_LOCKS = ON)

Open in new window

LVL 29

Expert Comment

by:Rich Weissler
ID: 39929070
I've had developers use automated tools which build some indexes, or modify indexes for them... and they don't realize the tool is turning off pagelocks or know what it is or care.  Zberteoc's quick alter statement should take care of it for you.  Alternately, you can drill down in Management Studio to the database > Table > Indexes ... then find the specific index you are receiving the error on.  Open it's properties, and select the 'options' page.  You can turn the page locks on for the index there.
Should look something like this.

Author Comment

ID: 39929582

Ok thanks but I have to use this script.
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

LVL 29

Expert Comment

by:Rich Weissler
ID: 39929890
I assume you 'have to use this script' to perform the maintenance.   Can you confirm that allow page locking his been disallowed for the one index?  I guess I should back up one level... are you receiving the error message for all indexes, or just for the one index that you specified after 'ERROR'?

Author Comment

ID: 39935576
I receive the message only for this index, it's the reason for that I search to exclude index with page locking disallowed.
LVL 29

Accepted Solution

Rich Weissler earned 500 total points
ID: 39935617
Oh, I see.   Check the values being returned to your script and ensure you aren't getting a NULL for Index.IsPageLockDisallowed.

Author Closing Comment

ID: 39951586

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Exceptions 3 37
TSQL DateADD update Question 4 27
Whats wrong in the below query? Any help would be appreciated... 2 14
Sql Query 4 14
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

911 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

16 Experts available now in Live!

Get 1:1 Help Now