Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

rebuild index

Posted on 2014-12-17
4
Medium Priority
?
104 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
[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
4 Comments
 
LVL 71

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 71

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 71

Accepted Solution

by:
Qlemo earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

715 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