Vb Script Automation for Listing the Database name in SQL SERVER
SET cn = CREATEOBJECT("ADODB.Connection")
SET cmd = CREATEOBJECT("ADODB.Command")
cmd.CommandTimeout = 1800
SET rs = CREATEOBJECT("ADODB.RecordSet")
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile ("C:\Users\pselladurai\Desktop\ListofDatabase.txt")
Set fil = fso.OpenTextFile("C:\Users\pselladurai\Desktop\ListofDatabase.txt", 8, true, 0)
'**** Change the connection string as required
cn.open "Provider=SQLOLEDB.1;Data Source=(local);Integrated Security=SSPI;Initial Catalog=Master"
cmd.activeconnection = cn
cmd.commandtext = "exec sp_helpdb"
SET rs = cmd.EXECUTE
'display = "Size" & vbtab & vbtab & "Name" & vbcrlf
WHILE rs.eof <> TRUE AND rs.bof <> TRUE
'display = display & trim(rs("db_size")) & vbtab & vbtab & rs("name") & vbcrlf
fil.WriteLine rs("name")
rs.movenext
WEND
cn.close
fil.Close
Wscript.Echo "Done."
No comments:
Post a Comment