Export (0) Print
Expand All

Persisting Custom Objects


Applies To: SQL Server 2016 Preview

You do not need to implement custom persistence for the custom objects that you create as long as their properties use only simple data types such as integer and string. The default implementation of persistence saves the metadata for your object along with the values of all its properties.

However, if your object has properties that use complex data types, or if you want to perform custom processing on property values as they are loaded and saved, you can implement the IDTSComponentPersist interface and its LoadFromXML and SaveToXML methods. In these methods you load from (or save to) the XML definition of the package an XML fragment that contains the properties of your object and their current values. The format of this XML fragment is not defined; it must only be well-formed XML.


When you implement custom persistence, you must persist all the properties of the object, including both inherited properties and custom properties that you have added.

Although the Sql Server Custom Connection Manager Sample does not require custom persistence for its three properties of type string, the following code shows an example of the custom code that would be required to persist the connection manager and its properties. The class that contains this code must implement the IDTSComponentPersist interface.

    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;
          case PERSIST_DATABASE:
            _databaseName = propertyNode.InnerText;
            _connectionString = propertyNode.InnerText;


    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;

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

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


Integration Services icon (small) Stay Up to Date with Integration Services

For the latest downloads, articles, samples, and videos from Microsoft, as well as selected solutions from the community, visit the Integration Services page on MSDN:

For automatic notification of these updates, subscribe to the RSS feeds available on the page.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft