0

データ変換サービス (DTS) 機能または SQL Enterprise Manager 2000 を使用して、レガシー システムからデータベースへのテキスト ファイル ダンプのスケジュールされたインポートを実行しています。

テキスト ファイル ダンプの不一致を処理するために、インポートの一部として VBS を使用して既にいくつかの変換を行っています。ほとんどの変換スクリプトは自動的に生成され、次のようになります。

****************************************
' Visual Basic Transformation Script
' Copy each source column to the 
' destination column
****************************************

Function Main()

    DTSDestination("db_column_title1") = DTSSource("txt_column_title1")
    DTSDestination("db_column_title2") = DTSSource("txt_column_title2")
    DTSDestination("db_column_title3") = DTSSource("txt_column_title3")
    DTSDestination("db_column_title4") = DTSSource("txt_column_title4")
    Main = DTSTransformStat_OK

End Function

データベースに追加の列としてテキスト ファイルの最終更新時刻を含めたいと思います。データベース テーブルに列を作成しましたが、import_dateこの VBScript でテキスト ファイルの最終変更時刻への参照を取得する方法がわかりません。

基本的に、次のようなものを追加したいと思います。

DTSDestination("import_date") = DTSSource.LastModTime

このようなプロパティをグーグルで検索してみましたが、何も見つかりませんでした.VBSとDTSはまだかなり漠然としているので、テキストファイルの変更時間をスクリプトへの参照として取得できるかどうかさえわかりません. .

4

1 に答える 1

0

The solution was to use ActiveX scripting objects in the generated transformation script, this allows me to get a direct reference to the imported text file. I can read the mod time form that instead of trying to find a ModTime property for DTSSource:

****************************************
' Visual Basic Transformation Script
' Copy each source column to the 
' destination column
****************************************

Function Main()

    // create a direct reference to the import file
    Dim oFSO
    Dim importFile

    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set importFile = oFSO.GetFile("\\server\file\path")

    // get mod time from the reference
    lastMod = importFile.DateLastModified

    DTSDestination("db_column_title1") = DTSSource("txt_column_title1")
    DTSDestination("db_column_title2") = DTSSource("txt_column_title2")
    DTSDestination("db_column_title3") = DTSSource("txt_column_title3")
    DTSDestination("db_column_title4") = DTSSource("txt_column_title4")

    // add the data here
    DTSDestination("import_date") = lastMod

    Main = DTSTransformStat_OK

End Function
于 2013-04-28T18:26:42.473 に答える