getSQLinfo.vbs 获得SQL数据/日志空间使用情况的脚本
作者 佚名
来源 ASP编程
浏览
发布时间 2013-07-09
获得SQL数据/日志空间使用,已使用的和未使用的空间的脚本 getSQLinfo.vbs ''scripttogetSQLDATA/LOGSpaceUsed,Spaceunused, andSpaceFree ''Author:FelipeFerreira,DanielMagrini ''Date:05/07/07 ''Version2,0 ''@@TOCHANGE:::SERVERNAME\Instance,domain\user,passwordANDDATABSE! ''____________________________________________________________________________ ConstForReading=1,ForWriting=2,ForAppending=8 SetoFSO=CreateObject("Scripting.FilesyStemObject") outputfile="CheckSqlDB_Size.txt" Setofile=oFso.OpenTextFile(outputfile,8,True) oFile.Writeline"######################################################" oFile.Writeline"Thiscommandexecutedin"&Date&"at"&Time&VbCrLf ''____________________________________________________________________________ CheckSQLData CheckSQLLOG ''##############GETSQLDATASPACEUSED,SPACETOTAL,SPACEFREE ''FunctioncheckSQL(strServer,strDB)inthefuturemakeitafunction.... SubCheckSQLDATA ConstadOpenDynamic=1,adLockOptimistic=3 DimstrQuery DimobjConnection,objRecordSet DimstrQueryResult,strQueryResult2 DimUsedDataSpace,TotalDataSpace,FreeDataSpace SetobjConnection=CreateObject("ADODB.Connection") SetobjRecordSet=CreateObject("ADODB.Recordset") objConnection.Open_ "Provider=SQLOLEDB.1;Server=192.168.8.10;UserID=sa;Password=lcx;Database=master;" strQuery="DBCCshowfilestats" objRecordSet.OpenstrQuery,objConnection,adOpenDynamic,adLockOptimistic ifobjRecordSet.eofThen ''nothingreturned wscript.echo"ERROR!!!" Else ''NOTE:TogetthevalueinMB64/1024=0.0625 DoUntilobjRecordSet.eof strQueryResult=objRecordSet.Fields("UsedExtents") UsedDataSpace=strQueryResult*0.0625 strQueryResult2=objRecordSet.Fields("TotalExtents") TotalDataSpace=strQueryResult2*0.0625 FreeDataSpace=TotalDataSpace-UsedDataSpace ''CleanData UsedDataSpace=Left(UsedDataSpace,4) FreeDataSpace=Left(FreeDataSpace,4) TotalDataSpace=Left(TotalDataSpace,4) ''PrintResultonScreen Wscript.echo"UsedSpace(MB)="&UsedDataSpace Wscript.Echo"FreeSpace(MB)="&FreeDataSpace Wscript.Echo"TotalSpace(MB)="&TotalDataSpace ''WriteonFile ofile.WriteLine"UsedDATASpace(MB)="&UsedDataSpace ofile.WriteLine"FreeDATASpace(MB)="&FreeDataSpace ofile.WriteLine"TotalDATASpace(MB)="&TotalDataSpace objRecordSet.MoveNext loop endif objRecordSet.Close objConnection.Close setobjConnection=nothing setobjRecordSet=nothing endsub SubCheckSQLLOG ConstadOpenDynamic=1,adLockOptimistic=3 DimstrQuery DimobjConnection,objRecordSet DimstrQueryResult,strQueryResult2 DimUsedLogSpace,TotalLogSpace,FreeLogSpace SetobjConnection=CreateObject("ADODB.Connection") SetobjRecordSet=CreateObject("ADODB.Recordset") objConnection.Open_ "Provider=SQLOLEDB.1;Server=192.168.8.10;UserID=sa;Password=lcx;Database=master;" strQuery="DBCCSQLPERF(LOGSPACE)" objRecordSet.OpenstrQuery,objConnection,adOpenDynamic,adLockOptimistic ifobjRecordSet.eofThen ''nothingreturned wscript.echo"ERROR!!!" Else DoUntilobjRecordSet.eof IfobjRecordSet.Fields("DatabaseName")="master"Then strQueryResult=objRecordSet.Fields("LogSize(MB)") strQueryResult2=objRecordSet.Fields("LogSpaceUSed( |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: 禁止QQ上网的vbs脚本代码下一篇: 用VBS检测Guest状态的脚本
关于getSQLinfo.vbs 获得SQL数据/日志空间使用情况的脚本的所有评论