カスタム オブジェクトの永続化

プロパティで integer や string などの単純なデータ型のみを使用している限り、カスタム オブジェクトのカスタムの永続性を実装する必要はありません。 既定の永続性の実装により、オブジェクトのメタデータがすべてのプロパティの値と共に保存されます。

ただし、オブジェクトが複合データ型を使用するプロパティを持つ場合や、プロパティ値の読み込み時と保存時にカスタム処理を実行する場合は、IDTSComponentPersist インターフェイスと、このインターフェイスの LoadFromXML メソッドおよび SaveToXML メソッドを実装することができます。 これらのメソッドで、オブジェクトのプロパティとプロパティの現在の値を含む XML フラグメントを、パッケージの XML 定義から読み込んだり、パッケージの XML 定義に保存したりします。 この XML フラグメントの形式は定義されていません。必要なのは、整形式の XML であるということだけです。

重要な注意事項重要

カスタムの永続性を実装するときは、継承したプロパティと追加したカスタム プロパティを含む、オブジェクトのすべてのプロパティを保存する必要があります。

SQL Server Custom Connection Manager サンプルでは、string 型の 3 つのプロパティのカスタムの永続性は不要ですが、次のコードでは接続マネージャーとそのプロパティの保存が必要なカスタム コードの例を示します。 このコードを含むクラスでは、IDTSComponentPersist インターフェイスを実装する必要があります。

  Private Const PERSIST_ELEMENT As String = "SqlConnectionManager"
  Private Const PERSIST_SERVER As String = "Server"
  Private Const PERSIST_DATABASE As String = "Database"
  Private Const PERSIST_CONNECTIONSTRING As String = "ConnectionString"

  Public Sub LoadFromXML(ByVal node As System.Xml.XmlElement, _
    ByVal infoEvents As Microsoft.SqlServer.Dts.Runtime.IDTSInfoEvents) _
    Implements Microsoft.SqlServer.Dts.Runtime.IDTSComponentPersist.LoadFromXML

    Dim propertyNode As XmlNode

    ' Make sure that the correct node is being loaded.
    If node.Name <> PERSIST_ELEMENT Then
      Throw New Exception("Persisted element is not of type " & PERSIST_ELEMENT)
    End If

    ' Load the three properties of the object from XML into variables.
    For Each propertyNode In node.ChildNodes
      Select Case propertyNode.Name
        Case PERSIST_SERVER
          _serverName = propertyNode.InnerText
        Case PERSIST_DATABASE
          _databaseName = propertyNode.InnerText
        Case PERSIST_CONNECTIONSTRING
          _connectionString = propertyNode.InnerText
      End Select
    Next

  End Sub

  Public Sub SaveToXML(ByVal doc As System.Xml.XmlDocument, _
    ByVal infoEvents As Microsoft.SqlServer.Dts.Runtime.IDTSInfoEvents) _
    Implements Microsoft.SqlServer.Dts.Runtime.IDTSComponentPersist.SaveToXML

    Dim elementRoot As XmlElement
    Dim propertyNode As XmlNode

    ' Create a new node to persist the object and its properties.
    elementRoot = doc.CreateElement(String.Empty, PERSIST_ELEMENT, String.Empty)

    ' Save the three properties of the object from variables into XML.
    propertyNode = doc.CreateNode(XmlNodeType.Element, PERSIST_SERVER, String.Empty)
    propertyNode.InnerText = _serverName
    elementRoot.AppendChild(propertyNode)

    propertyNode = doc.CreateNode(XmlNodeType.Element, PERSIST_DATABASE, String.Empty)
    propertyNode.InnerText = _databaseName
    elementRoot.AppendChild(propertyNode)

    propertyNode = doc.CreateNode(XmlNodeType.Element, PERSIST_CONNECTIONSTRING, String.Empty)
    propertyNode.InnerText = _connectionString
    elementRoot.AppendChild(propertyNode)

    doc.AppendChild(elementRoot)

  End Sub
    private const string PERSIST_ELEMENT = "SqlConnectionManager";
    private const string PERSIST_SERVER = "Server";
    private const string PERSIST_DATABASE = "Database";
    private const string PERSIST_CONNECTIONSTRING = "ConnectionString";

    public void LoadFromXML(System.Xml.XmlElement node,
      Microsoft.SqlServer.Dts.Runtime.IDTSInfoEvents infoEvents)
    {

      // Make sure that the correct node is being loaded.
      if (node.Name != PERSIST_ELEMENT)
      {
        throw new Exception("Persisted element is not of type " + PERSIST_ELEMENT);
      }

      // Save the three properties of the object from variables into XML.
      foreach (XmlNode propertyNode in node.ChildNodes)
      {
        switch (propertyNode.Name)
        {
          case PERSIST_SERVER:
            _serverName = propertyNode.InnerText;
            break;
          case PERSIST_DATABASE:
            _databaseName = propertyNode.InnerText;
            break;
          case PERSIST_CONNECTIONSTRING:
            _connectionString = propertyNode.InnerText;
            break;
        }
      }

    }

    public void SaveToXML(System.Xml.XmlDocument doc,
      Microsoft.SqlServer.Dts.Runtime.IDTSInfoEvents infoEvents)
    {

      XmlElement elementRoot;
      XmlNode propertyNode;

      // Create a new node to persist the object and its properties.
      elementRoot = doc.CreateElement(String.Empty, PERSIST_ELEMENT, String.Empty);

      // Save the three properties of the object from variables into XML.
      propertyNode = doc.CreateNode(XmlNodeType.Element, PERSIST_SERVER, String.Empty);
      propertyNode.InnerText = _serverName;
      elementRoot.AppendChild(propertyNode);

      propertyNode = doc.CreateNode(XmlNodeType.Element, PERSIST_DATABASE, String.Empty);
      propertyNode.InnerText = _databaseName;
      elementRoot.AppendChild(propertyNode);

      propertyNode = doc.CreateNode(XmlNodeType.Element, PERSIST_CONNECTIONSTRING, String.Empty);
      propertyNode.InnerText = _connectionString;
      elementRoot.AppendChild(propertyNode);

      doc.AppendChild(elementRoot);

    }
Integration Services のアイコン (小) 最新の Integration Services の入手

マイクロソフトが提供する最新のダウンロード、アーティクル、サンプル、ビデオ、およびコミュニティで選択されたソリューションについては、MSDN の Integration Services のページを参照してください。


これらの更新が自動で通知されるようにするには、ページの RSS フィードを定期受信します。

関連項目

タスク

カスタム オブジェクトのビルド、配置、およびデバッグ

概念

Integration Services 用のカスタム オブジェクトの開発