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
Solved

rebuild index

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Synchronize a new Active Directory domain with an existing Office 365 tenant
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…
Viewers will learn how the fundamental information of how to create a table.

790 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