Razvan Socol
3/21/2007 7:20:00 AM
Hello, moondaddy
If you want to optimize access to a certain property that will be used
when looping through objects using SMO, you can use the
SetDefaultInitFields method to specify that that property should be
initialized first (for all objects), not on access (for each object).
For example:
Dim t As DateTime
t = Now
Dim srv As New Microsoft.SqlServer.Management.Smo.Server(".
\SQLEXPRESS")
Dim sp As New Microsoft.SqlServer.Management.Smo.StoredProcedure
srv.SetDefaultInitFields(sp.GetType, "IsSystemObject")
For Each sp In srv.Databases("AdventureWorks").StoredProcedures
If Not sp.IsSystemObject Then
Debug.Print(sp.Name)
End If
Next
MsgBox(DateDiff(DateInterval.Second, t, Now))
On my system, the above code executes in less than 1 second (compared
to over 2 minutes if I remove the call to SetDefaultInitFields).
In this case, however, it would probably be better to use the method
suggested by Charles Wang, because it would probably work even faster.
Razvan