手机
当前位置:查字典教程网 >脚本专栏 >vbs >getSQLinfo.vbs 获得SQL数据/日志空间使用情况的脚本
getSQLinfo.vbs 获得SQL数据/日志空间使用情况的脚本
摘要:获得SQL数据/日志空间使用,已使用的和未使用的空间的脚本getSQLinfo.vbs'scripttogetSQLDATA/LOGSpac...

获得SQL数据/日志空间使用,已使用的和未使用的空间的脚本

getSQLinfo.vbs

'scripttogetSQLDATA/LOGSpaceUsed,Spaceunused,

andSpaceFree

'Author:FelipeFerreira,DanielMagrini

'Date:05/07/07

'Version2,0

'@@TOCHANGE:::SERVERNAMEInstance,domainuser,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(%)")

UsedLogSpace=(strQueryResult*strQueryResult2)/100

TotalLogSpace=strQueryResult

FreeLogSpace=TotalLogSpace-UsedLogSpace

'CleanData

UsedLogSpace=Left(UsedLogSpace,4)

FreeLogSpace=Left(FreeLogSpace,4)

TotalLogSpace=Left(TotalLogSpace,4)

'PrintResultonScreen

Wscript.echo"UsedSpace(MB)="&UsedLogSpace

Wscript.Echo"FreeSpace(MB)="&FreeLogSpace

Wscript.Echo"TotalSpace(MB)="&TotalLogSpace

'WriteonFile

oFile.WriteLine"UsedLOGSpace(MB)="&UsedLogSpace

oFile.WriteLine"FreeLOGSpace(MB)="&FreeLogSpace

oFile.WriteLine"TotalLOGSpace(MB)="&TotalLogSpace

oFile.close

ExitDo

EndIf

objRecordSet.MoveNext

loop

endif

objRecordSet.Close

objConnection.Close

setobjConnection=nothing

setobjRecordSet=nothing

endsub

WSCript.Quit

【getSQLinfo.vbs 获得SQL数据/日志空间使用情况的脚本】相关文章:

可以将Bat转换位VBS文件的VBS脚本

用vbs 取得收藏夹里的所有链接名称和URL的脚本

VBS 路由重启脚本

用vbs实现注册表开关的脚本

用vbs删除某些类型文件和磁盘空间报告的脚本

用vbs实现本地添加用户的脚本

用vbs遍历文件并随机显示的脚本

vbs判读盘符被双击的脚本

一个扩展时间段的dir命令的vbs脚本

用vbs通过135端口执行命令的脚本

精品推荐
分类导航