Richard's profileRichard Siddaway's BlogPhotosBlogLists Tools Help

Blog


    June 25

    SQL Server autoclose

    Buck Woody blogged about SQL Server autoclose and how it should be set to being off  - http://blogs.msdn.com/buckwoody/archive/2009/06/24/sql-server-best-practices-autoclose-should-be-off.aspx 

    I’m doing a lot with SQL Server and PowerShell at the moment and it started me thinking that I could easily set this property in PowerShell.

    001
    002
    003
    004
    005
    006
    007
    008
    009
    010
    $Server = New-Object Microsoft.SqlServer.Management.Smo.Server("SQL08")
    $Server.databases | select Name, Autoclose
    foreach ($db in $Server.Databases){
        if (!$db.IsSystemObject){
            $db.Autoclose = $false
            $db.Alter()
        }
    }
    $Server = New-Object Microsoft.SqlServer.Management.Smo.Server("SQL08")
    $Server.databases | select Name, Autoclose

     

    Create a server object and display the databases, selecting name and the autoclose property.  Its boolean so we get true or false back.

    We can iterate through the database collection. Test if the database is a system database and set autoclose to false (we don’t want autoclose to happen).  A call to Alter() saves the change.

    Finally we can recreate the server object and  redisplay the autoclose property.

    Technorati Tags: ,

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.
    Richard Siddaway has turned off comments on this page.

    Trackbacks

    The trackback URL for this entry is:
    http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!2430.trak
    Weblogs that reference this entry
    • None