Solved

question about rebuild index with smo

Posted on 2014-03-13
7
365 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

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

Question has a verified solution.

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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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…

770 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