Deleting old files through SSIS?!

  • What happens when you hover over oFile.Delete(true) in break mode?

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • I have not been able to get the script task to go into break mode. In fact, I was reading a couple of articles that said you can't put the script task in break mode. At best, I can put in some msgbox's to see the value of variables.

    Things will work out.  Get back up, change some parameters and recode.

  • I just did it. All you have to do is click on the line(s) of code then click on debug.

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Ok, this is good. I have no idea what you are talking about, but I am learning. So this is good.

    1) I am in the task script.

    2) I click the line of code and it inserts a breakpoint.

    3) I click debug

    4) I then click step into (I also tried F5)

    5) It then opens up a another instance of Visual Studio shell. I see all my projects. I have no idea what to do now or if it it is looking at the other instance of Visual Studio with my script.

    Things will work out.  Get back up, change some parameters and recode.

  • One problem is that the example code that you are using appears to be an older version.

    If you click back on the first instance you will see some errors.

    You will notice errors with the DECLARE Statements.

    You must specify the type of variable, e.x. Object, etc. in the DECLARE Statement.

    Also the script task should be within a ForEachLoop Container.

    I would goggle for a better example.

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • I won't say much more about the actual script itself. I think you are close, and I gave you a solution in C# that all you have to do is port to VB.NET.

    I will say one thing about your variable names. Use of the Hungarian naming convention is unacceptable for use in .NET code, i.e. in my days as a .NET Development Team Lead I would have failed you on code review. I won't re-state everything others have already stated, and probably more eloquently than I am capable of, so I'll provide this link:

    http://10rem.net/articles/net-naming-conventions-and-programming-standards---best-practices

    Look for section "Why Hungarian Has Fallen Out of Favor with .NET". If you want to skip the history lesson jump straight to the paragraph in that section beginning with "Along comes .NET and just about everything is an object".

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Alright!!!

    I got it to work. Finally, I can close another task.

    Thanks for pointing me in the right direction. I am still just using a script task.

    Tony

    P.S. Here is the final code that I was able to make work:

    Dim iDaysOld As Integer

    Dim sDebug As String

    Dim FileFound As String

    Dim FI As FileSystemInfo

    'Initilize variable

    '******************

    sDebug = "N"

    iDaysOld = CInt(Dts.Variables("User::DaysBack").Value) 'the variable DaysBack can be altered as needed.

    'Walk through each file in this folder collection.

    '*************************************************

    For Each FileFound In Directory.GetFiles(CStr(Dts.Variables("User::FileFolder").Value), "*.bak")

    FI = My.Computer.FileSystem.GetFileInfo(FileFound)

    If FI.LastWriteTime < (DateTime.Now.AddDays(-iDaysOld)) Then

    'If we are debugging, then just show a messagebox. If this is not a debug,

    'delete the file.

    '**************************************************************************

    If sDebug = "Y" Then

    MsgBox("File found that needs to be deleted: " + FileFound, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "File Deletion")

    Else

    MsgBox("about to delete")

    FI.Delete()

    MsgBox("File deleted: " + FileFound, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "File Deletion")

    Exit For

    End If

    End If

    Next

    MsgBox("All finished")

    'Cleanup

    FI = Nothing

    'send back result

    '****************

    Dts.TaskResult = ScriptResults.Success

    Things will work out.  Get back up, change some parameters and recode.

  • Excellent! HTH

    PS Read that article about variable names 😉

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Were you able to get the breakpoints to work and step through the code?

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Thanks WebTechie. Old thread with a bit of necro I know, but you just saved me an hour of wall-banging trying to remember how to do this. 🙂


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

Viewing 10 posts - 16 through 24 (of 24 total)

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