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”

~~~