Finding Database Free space using DTS

  • My requirement is to find the Free Space of DB and send a mail to the user.

    Im trying to use DTS package,

    Is it possible to find the free space of Database using DTS Package?

    Is there any MS SQL query available to find the free space of the Database?

    Im looking for a single query to find the freespace instead of Stored Procedure.

    In DTS package,

    When i try to use a stored procedure, i cant able to create parameters. why?

    What im trying to do in DTS package is,

    I have a stored procedure, im trying to execute that. After i execute that the resultset should be passed as output parameter or global variable. I want to use that value in the activeX script.

    Thanks,

    MRK

  • The way to do this is call the stored procedure from the ActiveX script. Then you can get an output variable or result set.

    http://www.thescripts.com/forum/thread498718.html

    DTS doesn't do a great job of passing along information. If this is for just one database, you could set global variables to the result of the query. You can also turn the stored procedure into a query.

  • HI,

    Im trying to execute the below procedure. But we are facing some techincal problem in this while implementing it into the DTS Package.

    CREATE procedure DiskSpace_Size

    AS

    SET NOCOUNT ON

    DECLARE @disksize Decimal(15,2)

    SET NOCOUNT ON

    BEGIN

    CREATE TABLE #T1(DRVLETTER CHAR(1),DRVSPACE INT)

    INSERT INTO #T1 EXEC master.dbo.xp_fixeddrives;

    select @DiskSize =(SELECT DRVSPACE FROM #T1 WHERE DRVLETTER='D');

    Drop TABLE #T1

    return @DiskSize

    end

    Execution:

    ------------

    DECLARE @ReturnValue int

    EXEC @ReturnValue = DiskSpace_Size

    SELECT ReturnValue=@ReturnValue

    While executing like this im getting the freespace. But when using DTS Package.

    If i click on 'Parameters' then click on 'Create/edit Parameter' That value is not getting shown in the Returnvalue.

    The Parameter "ReturnValue" is not getting the value.

    How to resolve this?

    It would be better if we find the freespace of DiskDrive in a single query.

    So that it will work fine.

    MRK.

  • Sometimes DTS can be a right pain in the a$$. :hehe:

    What you can do to work around this is create the DiskSpace_size procedure with all of the lines involving the temporary table commented out.

    CREATE procedure DiskSpace_Size

    AS

    SET NOCOUNT ON

    DECLARE @disksize Decimal(15,2)

    SET NOCOUNT ON

    BEGIN

    --CREATE TABLE #T1(DRVLETTER CHAR(1),DRVSPACE INT)

    --INSERT INTO #T1 EXEC master.dbo.xp_fixeddrives;

    --select @DiskSize =(SELECT DRVSPACE FROM #T1 WHERE DRVLETTER='D');

    --Drop TABLE #T1

    return @DiskSize

    end

    GO

    You can then create your ExecuteSQL Task in the DTS to execute the procedure:

    DECLARE @rc INT

    EXEC @rc = DiskSpace_size

    SELECT @rc AS diskspace

    Once you've created the code hit the parameters button and you should be able to assign 'diskpace' to a globalvariable.

    Complete the ExecuteSQL task creation as necessary and then go back to the stored procedure, uncomment the lines and recreate the procedure.

    ... As I said, pain in the a$$! 😀



    Ade

    A Freudian Slip is when you say one thing and mean your mother.
    For detail-enriched answers, ask detail-enriched questions...[/url]

  • Hi,

    Thank you very much.

    The problem is with my output parameter.

    i have resolved it.

    Thanks for all your support.

    MRK.

  • HI,

    Im facing a trouble here.

    For "D" drive i executed Procedure.

    The out put parameter is Diskspace.

    The Global variable is also Diskspace and the value 755 got stored in that.

    And the output came as 755. (755 MB freespace)

    This 755 is stored in Global variable. and the Package is working fine.

    Then i tried to find freespace for "K" drive,

    This time also the same 755 is coming.

    It means the Global variable is not getting updated.

    Why this global variable is not getting updated??

    Can anybody help me to resolve this?

    MRK.

  • How did you do this for the K drive? Did you recreate the procedure with a 'K' in the WHERE clause instead of a 'D'? Or something different?

    You might also want to change your procedure for usability, making @drive CHAR(1) an input variable to the procedure and changing the WHERE clause to incorporate the new variable; this would make it more reusable.



    Ade

    A Freudian Slip is when you say one thing and mean your mother.
    For detail-enriched answers, ask detail-enriched questions...[/url]

  • Hi,

    Yes, I recreated the procedure with a 'K' in the WHERE clause instead of a 'D'.

    Whatever it may be it should return the correct value but only the previous value is getting assigned to the Global Variable..

    The freespace of "K" drive is 9872 but still the global variable is not getting updated and the freespace of "C" drive is showing in the Global variable.

    Why this global value is not getting updated?

    MRK.

  • Is the K drive actually a mapped drive to a disk on another server? If so this won't show up on xp_fixeddrives.



    Ade

    A Freudian Slip is when you say one thing and mean your mother.
    For detail-enriched answers, ask detail-enriched questions...[/url]

  • Hi,

    Its working fine in SQL Analyser.

    Showing the K Drive freespace properly.

    K Drive is a proper drive only not another server.

    But When i implement in DTS Package, the output globalvariable value is not getting updated.

    Why the global variable is not getting updated based on the output?

    MRK.

  • I've set up and ran a test on my dev machine here. When I've changed drive letters in the stored procedure, the correct value has been output to the global variable. The only condition under which this doesn't happen has been when the drive letter doesn't exist; the global variable value does not change from the previous drive run.

    At the moment I can only suggest:

    1. Checking that your SQL connection is to the correct server

    2. Run the procedure for the C drive and then the D drive and check that the global variable value changes correctly at this point. Post back the results of these checks and while that's running I'll have another think. :crazy:



    Ade

    A Freudian Slip is when you say one thing and mean your mother.
    For detail-enriched answers, ask detail-enriched questions...[/url]

  • Hi,

    When im Testing with "K" drive the value is coming and the global variable is getting updated and displayed the value 9722

    Next when i test with "D" drive the global variable is not getting updated only the previous value is getting displayed as 9722 instead of 780.

    I want to know why the global variable is not getting updated for every run?

    MRK.

  • Hi,

    Im using this procedure

    ALTER procedure Size_DiskDrive

    @driveletter char(1)

    AS

    DECLARE @flag int

    DECLARE @dbsize Decimal(15,2),

    @TBexist int

    BEGIN

    select @TBexist = count(*) from sysobjects where type = 'U' and name = 'Test1'

    if (@TBexist = 0)

    BEGIN

    CREATE TABLE Test1(DRVLETTER CHAR(1),DRVSPACE INT)

    INSERT INTO Test1 EXEC master.dbo.xp_fixeddrives;

    select @DBSize =(SELECT DRVSPACE FROM Test1 WHERE DRVLETTER= @driveletter)

    PRINT 'Success'

    PRINT @TBexist

    End

    else

    Begin

    INSERT INTO Test1 EXEC master.dbo.xp_fixeddrives;

    select @DBSize =(SELECT DRVSPACE FROM Test1 WHERE DRVLETTER= @driveletter)

    PRINT 'Failure'

    end

    Truncate Table Test1

    --Drop TABLE Test1

    PRINT @DBSize

    Return @DBSize

    end

    Im using this statements in Execute SQL Tasks to execute the above procedure.

    DECLARE @rc decimal(15, 5)

    EXECUTE @rc = Size_DiskDrive 'K'

    SELECT @rc AS freespace

    This automatically creates the parameter "freespace" i have created a global variable "freespace".

    On executing first time im getting the correct value as "9222".

    But If i change the input parameter as "D" instead of "K" like

    EXECUTE @rc = Size_DiskDrive 'D'

    im getting the same value "9222" again instead of "7332"

    The new value is not getting updated in the global variable.

    If i try this in SQL Analyzer its working fine for every execution. But in DTS the Golbal variable is not getting updated. why?

    Can you pls help me to resolve this issue?

    Thanks in advance,

    MRK.

Viewing 13 posts - 1 through 12 (of 12 total)

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