FTPサーバーからファイルをインポートするパッケージを作成しました。新しいファイルのみを処理する必要があります。つまり、既に読み込まれている(テーブルに保持されている)ファイルを除外する必要があります。SSISスクリプトタスク - DataTableの入力に失敗しました
まず、SQL実行タスクを実行して、 "AlreadyLoadedFiles"オブジェクト変数を設定します。次に、スクリプトタスク内で処理する必要があるファイルを特定しようとします。最初にFTPサーバー上のファイルの名前をロードし、既にロードされているファイルを削除します。
FTP上にあるファイルの名前を取得するのに問題はありませんが、OleDBDataAdapterにオブジェクト変数 "AlreadyLoadedFiles"を入力すると、結果のデータテーブルが空になり、その理由がわかりません。
' Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic
' The ScriptMain class is the entry point of the Script Task.
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Xml
Imports System.Data.OleDb
Imports System.Collections.Specialized
Imports System.Text.RegularExpressions
<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Public Sub Main()
'
Dim vs As Variables
Dim dt As New DataTable
Dim da As New OleDbDataAdapter()
'We need to go to or FTP server
Dts.VariableDispenser.LockOneForRead("FTPSourceDirectory", vs)
Dim cm As ConnectionManager = Dts.Connections("FTPServer")
Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(Nothing))
ftp.Connect()
ftp.SetWorkingDirectory(vs("FTPSourceDirectory").Value.ToString())
vs.Unlock()
'We now need to get ourselves the files we have already seen
Dts.VariableDispenser.LockOneForRead("AlreadyLoadedFiles", vs)
da.Fill(dt, vs("AlreadyLoadedFiles").Value)
MessageBox.Show(dt.Rows.Count)
vs.Unlock()
Dim foldernames() As String
Dim filenames() As String
'Get the list of files that are there on the FTP server
ftp.GetListing(foldernames, filenames)
Dim dr As DataRow
Dim ss As StringCollection = New StringCollection()
Dim iFileCount As Integer
If filenames Is Nothing Then
MessageBox.Show("No Files Found")
Exit Sub
Else
'Need to loop through all the files found
For iFileCount = 0 To filenames.GetUpperBound(0)
'First we add all of the found files to the Array (Object) but only if they are CSV files
Dim re As New Regex("^co_users_report_\d{4}-\d{2}-\d{2}\.csv$")
If re.IsMatch(filenames(iFileCount).ToString()) Then
ss.Add(filenames(iFileCount).ToString())
Dts.Events.FireInformation(0, "", filenames(iFileCount).ToString(), "", 0, True)
End If
For Each dr In dt.Rows
Dts.Events.FireInformation(0, "", dr(0).ToString(), "", 0, True)
If dr(0).ToString() = filenames(iFileCount).ToString() Then
MessageBox.Show(dr(0).ToString)
Dts.Events.FireInformation(0, "", "Removed " & filenames(iFileCount).ToString() & " from array because it was previously loaded.", "", 0, True)
ss.Remove(filenames(iFileCount).ToString())
Exit For
End If
Next
Next
End If
Dts.VariableDispenser.LockOneForWrite("FilesForFTPDownload", vs)
vs(0).Value = ss
vs.Unlock()
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
私は私はあなたが複数のコンポーネントにこれを破ることをお勧めSQL Serverの(SSIS)2008 R2 64ビット