Solved

rebuild index

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

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 70

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 70

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VMware PVSCSI SQL Server 2016 AlwaysOn 2 37
SQL Job Failed 6 31
Add incrementing numbers to log file in powershell 1 20
Active Directory Powershell Script 9 44
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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…

752 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