Returning Disk space information from an SP

  • Hi,

    I an attempting to call the Scripting.filesystemobject dll from a SQL sp to return me the freespace and totalsize properties of the drives on a db server.

    I get the freespace value no problem, driveletter back ok, but when I try the Totalsize property whammo. The error I get is 'ODSOLE Extended Procedure Out of present range.'

    The dll works fine if called from asp so I am at a bit of a loss.

    Can anyone shed some light on the error or suggest another method of finding out this information? Any help replies gratefully received.

    Richard Hudson

    Code snippet:

    declare @obj int

    declare @hr int

    declare @driveobj int

    declare @size int

    exec @hr=sp_oacreate 'Scripting.Filesystemobject',@obj out

    if @hr = 0

    begin

    EXEC @hr = sp_OAMethod @obj , 'GetDrive',@DriveObj Out, 'C:'

    if @hr = 0

    EXEC @hr = sp_OAGetProperty @DriveObj , 'TotalSize',@size Out

    if @hr <> 0

    EXEC sp_OAGetErrorInfo @DriveObj

    else

    EXEC sp_OAGetErrorInfo @DriveObj

    end

    print @size

    EXEC sp_oadestroy @DriveObj

    EXEC sp_oadestroy @Obj

  • changed @size to bigint, get different error. Tried numeric, error. Float returns null.

    Expect that the drive size (in bytes) exceeds the int range. Not sure why bigint doesn't work.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

  • Thanks for the replies Steve.

    I've tried xp_fixeddrives but it only gives free space. What I am after is the total size so I can give the percentage freespace as this is an immediate easy metric to visualise when in the 'why has the site gone down' and everyone wearing headless chicken suit kind of situations.

  • ... In the end I wrote a VB dll wrapper around the filesystemobject which seemed to work ok when call from the SP.

    Richard

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply