WARDY IT Solutions Blog

A blog on Brisbane's leading SQL Server consulting and training company

DMO and SMO AutoShrink

The following SQLDMO and SMO VBScript code snippets can be used to check each database on a SQL Server instance and identify any databases where the AutoShrink database option is enabled.  Note the DBOptions Class in SQLDMO has been moved to DatabaseOptions in SMO.

~~~ DMO Example ~~~

Dim db
Dim oDMOServer

Set oDMOServer = CreateObject("SQLDMO.SQLServer")

oDMOServer.LoginSecure = True
oDMOServer.Connect "(local)"

For Each db In oDMOServer.Databases
    If db.DBOption.AutoShrink = True Then
        MsgBox db.Name & " - Auto Shrink Enabled"
    End If
Next

oDMOServer.DisConnect
Set oDMOServer = Nothing

MsgBox "Done"

~~~

~~~ SMO Example ~~~

Dim db
Dim oSMOServer

Set oSMOServer = CreateObject("Microsoft.SQLServer.Management.SMO.Server")

For Each db In oSMOServer.Databases
    If db.DatabaseOptions.AutoShrink = True Then
        MsgBox db.Name & " - Auto Shrink Enabled"
    End If
Next

Set oSMOServer = Nothing

MsgBox "Done"

~~~

Published Tuesday, March 07, 2006 4:02 PM by peter@wardyit.com

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

SQL Maintenance Tips said:

January 2, 2009 12:54 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit