我创建了一个正常运行的SSIS包,它将行从平面文件拉到SQL表中。一旦超过10天,我只需要能够删除表中的旧行。
唯一的问题是,没有日期列,我想知道是否有办法使用源文件中的DateLastModified
属性?我不确定这是否可以通过脚本任务或其他方式完成?
您的建议将不胜感激。 : - )
所以我试图通过创建FileDate变量以及FilePath和SourceFolder变量来包含源文件的日期。我通过添加派生列,Date_Imported w /表达式@ [User :: FileDate]来利用FileDate变量。为FilePath变量分配位置“d:\ inputfiles * .txt”,如下面的代码所示。 SourceFolder的值为“D:\ InputFiles \”。 但是,我收到的是“调用目标已抛出异常。
System.MissingMemberException:找不到类型为'FileSystemObject'的公共成员'GetFiles'。“
以下是我的脚本任务内容,用于删除超过10天的记录;请忽略任何注释掉的线条,因为我一直在尝试不同的事情......我感谢您提供的任何指导:
Public Sub Main()
' Add your code here
Dim FilePath As String
'Dim SourceFolder As String
Dim iMaxAge = 10
Dim oFSO = CreateObject("Scripting.FileSystemObject")
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
myConnection = New SqlConnection("server = localhost; uid=sa; pwd=; database=StampsProj")
FilePath = "d:\inputfiles\*.txt"
'SourceFolder = "d:\inputfiles"
'SourceFolder.ReadOnly = True
'To delete records, older than 10 days from AddUpIn table
'For Each oFile In oFSO.GetFolder(SourceFolder).Files
For Each oFile In oFSO.GetFiles(Dts.Variables("User::SourceFolder"))
Dim FileDate As Date = oFile.DateLastModified
If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then
'If DateDiff("d", oFile.FileDate, Now) > iMaxAge Then
myCommand = New SqlCommand("Delete from AddUpIn", myConnection)
End If
Next
End Sub
答案 0 :(得分:0)
听起来您需要在导入表中添加日期时间列,并将其值设置为运行导入的日期。或者创建一个单独的FileImport表,记录文件名和标识符,然后将标识符添加到导入表中,以便您可以识别要删除的行。