Solved

rebuild index

Posted on 2014-12-17
4
96 Views
Last Modified: 2014-12-17
Hello,

In the following script, $Index.IsPageLockDisallowed -eq $false is not applied and rebuild index failed  :
if ($Average_Fragmentation -gt 30.00 -and $Index.IsDisabled -eq $false -and $Index.IsPageLockDisallowed -eq $false)

            {
                  
                  Try {  
                  $index.Rebuild();
      
            
            }
      
                  Catch [exception] {                
                  LogIt  ("ERROR - " + $_.Exception) $true                
                              
                  Continue                
            }  
                  
            }

Why?

Thanks
0
Comment
Question by:bibi92
  • 3
4 Comments
 
LVL 69

Expert Comment

by:Qlemo
ID: 40505788
Probably that property does not exist? Difficult without seeing the code creating $Index.
It's also no good style to compare against $false or $true literals, unless there are very specific circumstances (causing implicit conversion for example). Use either -not or ! (the latter being the alias of -not):
if ($Average_Fragmentation -gt 30.00 -and !$Index.IsDisabled -and !$Index.IsPageLockDisallowed)

Open in new window

0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40505809
Hmm, this almost the same as your question http://www.experts-exchange.com/Q_28387484.html, but knowing you I'm not certain you really tested before accepting ... But at least we know now that you use a SMO object for that.
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40505822
Looked up the SMO Index object, and the property is called DisallowPageLocks. See http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.index_members(v=sql.90).aspx

I recommend to always set set-StrictMode –Version "latest", so you get an error if you explicitly reference an invalid property, unknown or uninitialised var, or for similar pitfalls.
0
 

Author Closing Comment

by:bibi92
ID: 40506387
Thanks
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

822 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