Solved

question about rebuild index with smo

Posted on 2014-03-13
7
369 Views
Last Modified: 2014-03-24
Hello,

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 {  
                  $index.Rebuild();
                  $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                
                  Continue                
            }  
                  
      
      }

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

Why ?

Thanks
0
Comment
Question by:bibi92
  • 3
  • 3
7 Comments
 
LVL 26

Expert Comment

by:Zberteoc
ID: 39927747
Maybe this helps:

http://mytechmantra.com/LearnSQLServer/Index-cannot-be-reorganized-because-page-level-locking-is-disabled/

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

0
 
LVL 30

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.
0
 

Author Comment

by:bibi92
ID: 39929582
Hello,

Ok thanks but I have to use this script.
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 30

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'?
0
 

Author Comment

by:bibi92
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.
Thanks
0
 
LVL 30

Accepted Solution

by:
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.
0
 

Author Closing Comment

by:bibi92
ID: 39951586
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query help 15 51
query output (script) from a stored procedure 4 36
Help needed in sql query 4 28
Using datetime as triggers 2 18
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

756 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