dcsimg
1 Sub subEnumerateDBBackups
2	Dim oApp        'As SQLDMO.Application
3	Dim oServer     'As SQLDMO.SQLServer
4	Dim oDatabase   'As SQLDMO.Database
5	Dim oNames      'As SQLDMO.NameList
6	Dim oName       'As Variant
7	Dim Connection1 'As Variant
8	Dim sMsgWindow	'As String
9
10	Set oApp = CreateObject("SQLDMO.Application")
11	Set oNames = oApp.ListAvailableSQLServers()
12
13	on error resume next
14
15	For Each oName In oNames
16		Set oServer = CreateObject("SQLDmo.SqlServer")
17
18		oServer.LoginSecure = True
19		oServer.Connect oName
20		if err.number <> 0 then
21			strErrorMsg = strErrorMsg & "" & vbCRLF
22			strErrorMsg = strErrorMsg & "trouble connecting to " & oName & vbCRLF
23			strErrorMsg = strErrorMsg & "" & vbCRLF
24
25			err.Clear
26	    		call writefile("C:\sqlbackupinfo.txt",strErrorMsg)
27			strErrorMsg = ""
28		end if 
29	    
30
31			strDBBackupList = ""
32			set objDBList = new clsServerBackupInfoList
33				objdblist.SQLServer = oName
34				strDBBackupList = strDBBackupList & objdblist.SQLServer & vbCRLF
35				while not objDBList.EOF
36					strDBBackupList = strDBBackupList & objDBList.Database & vbTab
37
38
39
40					set objDBInfo = new clsDBBackupInfo
41					objDBInfo.SQLServer = objdblist.SQLServer
42					objDBInfo.Database	= objDBList.Database
43					strDBBackupList = strDBBackupList & "Last Backup: " & 
                                        objdbinfo.StartTime & " Result " & objdbinfo.Success & " " & 
                                        objdbinfo.Message & " " & objdbinfo.Plan & vbCRLF
44					set objDBInfo = nothing
45					objDBList.MoveNext
46				Wend
47			call writefile("C:\sqlbackupinfo.txt",strDBBackupList)
48			set objDBList = nothing
49	Next
50
51	oServer.DisConnect
52	Set oServer = Nothing
53
54	oApp.Quit
55	Set oApp = Nothing 
56 End Sub