国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

getSQLinfo.vbs 獲得SQL數據/日志空間使用情況的腳本

2020-07-26 11:56:01
字體:
來源:轉載
供稿:網友
獲得SQL數據/日志空間使用,已使用的和未使用的空間的腳本

getSQLinfo.vbs
'script to get   SQL DATA/LOG Space Used, Space unused, 
and Space Free 
'Author: Felipe Ferreira, Daniel Magrini
'Date: 05/07/07
'Version 2,0

'@@TO CHANGE::: SERVERNAME/Instance, domain/user, password AND DATABSE!

'____________________________________________________________________________
Const ForReading = 1, ForWriting = 2, ForAppending = 8 
Set oFSO = CreateObject("Scripting.FilesyStemObject") 
outputfile = "CheckSqlDB_Size.txt" 
Set ofile = oFso.OpenTextFile(outputfile,8, True)
oFile.Writeline "######################################################"
oFile.Writeline "This command executed in " & Date & " at " & Time & VbCrLf
'____________________________________________________________________________

CheckSQLData
CheckSQLLOG


'############## GET SQL DATA SPACE USED, SPACE TOTAL, SPACE FREE
'Function checkSQL(strServer,strDB)   in the future make it a function....
Sub CheckSQLDATA
Const adOpenDynamic = 1, adLockOptimistic = 3
Dim strQuery
Dim objConnection, objRecordSet 
Dim strQueryResult, strQueryResult2
Dim UsedDataSpace, TotalDataSpace, FreeDataSpace
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open _
   "Provider=SQLOLEDB.1;Server=192.168.8.10;User ID=sa;Password=lcx;Database=master;"

strQuery = "DBCC showfilestats"
   objRecordSet.Open strQuery, objConnection, adOpenDynamic, adLockOptimistic
   if objRecordSet.eof Then
       'nothing returned
    wscript.echo "ERROR!!!"
   Else 

'NOTE : To get the value in MB   64 / 1024 = 0.0625
   Do Until objRecordSet.eof 
      strQueryResult = objRecordSet.Fields("UsedExtents")
    UsedDataSpace = strQueryResult * 0.0625
    strQueryResult2 = objRecordSet.Fields("TotalExtents")
    TotalDataSpace = strQueryResult2 * 0.0625
    FreeDataSpace = TotalDataSpace - UsedDataSpace

    'Clean Data
    UsedDataSpace = Left(UsedDataSpace,4)
    FreeDataSpace = Left(FreeDataSpace,4)
    TotalDataSpace = Left(TotalDataSpace,4)

    'Print Result on Screen
    Wscript.echo "Used Space(MB) = " & UsedDataSpace 
    Wscript.Echo "Free Space(MB) = " & FreeDataSpace
    Wscript.Echo "Total Space(MB) = " & TotalDataSpace

    'Write on File
    ofile.WriteLine "Used DATA Space(MB) = " & UsedDataSpace
    ofile.WriteLine "Free DATA Space(MB) = " & FreeDataSpace
    ofile.WriteLine "Total DATA Space(MB) = " & TotalDataSpace

      objRecordSet.MoveNext
   loop
   end if
objRecordSet.Close
objConnection.Close 
set objConnection = nothing
set objRecordSet = nothing
end sub

Sub CheckSQLLOG
Const adOpenDynamic = 1, adLockOptimistic = 3
Dim strQuery
Dim objConnection, objRecordSet 
Dim strQueryResult, strQueryResult2
Dim UsedLogSpace, TotalLogSpace, FreeLogSpace
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open _
   "Provider=SQLOLEDB.1;Server=192.168.8.10;User ID=sa;Password=lcx;Database=master;"

strQuery = "DBCC SQLPERF(LOGSPACE)"
   objRecordSet.Open strQuery, objConnection, adOpenDynamic, adLockOptimistic
   if objRecordSet.eof Then
       'nothing returned
    wscript.echo "ERROR!!!"
   Else 


   Do Until objRecordSet.eof 
    If objRecordSet.Fields("Database Name") = "master" Then

   
     strQueryResult = objRecordSet.Fields("Log Size (MB)")
     strQueryResult2 = objRecordSet.Fields("Log Space USed (%)")
     UsedLogSpace = (strQueryResult * strQueryResult2) / 100
     TotalLogSpace = strQueryResult
     FreeLogSpace = TotalLogSpace - UsedLogSpace

     'Clean Data
     UsedLogSpace = Left(UsedLogSpace,4)
     FreeLogSpace = Left(FreeLogSpace,4)
     TotalLogSpace = Left(TotalLogSpace,4)

     'Print Result on Screen
     Wscript.echo "Used Space(MB) = " & UsedLogSpace 
     Wscript.Echo "Free Space(MB) = " & FreeLogSpace
     Wscript.Echo "Total Space(MB) = " & TotalLogSpace

     'Write on File
     oFile.WriteLine "Used LOG Space(MB) = " & UsedLogSpace
     oFile.WriteLine "Free LOG Space(MB) = " & FreeLogSpace
     oFile.WriteLine "Total LOG Space(MB) = " & TotalLogSpace

     oFile.close

     Exit Do

    End If

      objRecordSet.MoveNext
   loop
   end if
objRecordSet.Close
objConnection.Close 
set objConnection = nothing
set objRecordSet = nothing
end sub
WSCript.Quit 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 诸暨市| 民县| 眉山市| 新营市| 晋城| 沙洋县| 蕲春县| 深泽县| 滕州市| 西和县| 靖州| 铁力市| 焦作市| 白朗县| 措勤县| 灌南县| 买车| 黎平县| 武义县| 河北区| 南丹县| 辽宁省| 扶余县| 全州县| 安平县| 光山县| 雷山县| 翁源县| 礼泉县| 昭平县| 大渡口区| 陇川县| 聂拉木县| 甘洛县| 丰都县| 额济纳旗| 库尔勒市| 华蓥市| 阜阳市| 绵竹市| 麻栗坡县|