Solved

rebuild index

Posted on 2014-12-17
4
93 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 68

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 68

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 68

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

707 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

12 Experts available now in Live!

Get 1:1 Help Now