Solved

question about rebuild index with smo

Posted on 2014-03-13
7
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 27

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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Removing SCCM 2016 4 53
databases from multiple applications - same instance 6 40
Remove () 10 41
DMV Script to find how many times statistics are utilized 2 30
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

751 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