Persisting Data Source Objects

The data source object can be persisted to a file. Any child objects of the data source object, such as sessions, commands, or rowsets, are not persisted with the data source object. The DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO property controls whether sensitive authentication information, such as the password, is persisted. If it is persisted, the DBPROP_AUTH_PERSIST_ENCRYPTED property controls whether it is persisted in encrypted form. The provider can make both of these properties read-only to control whether sensitive information can be persisted.

To persist a data source object to a file, the consumer calls IPersistFile::Save; the data source object can be in an uninitialized or initialized state. To reload the data source object, the consumer calls IPersistFile::Load on an uninitialized data source object; if the data source object is initialized, Load returns DB_E_ALREADYINITIALIZED. After loading the persisted file, the consumer must call IDBInitialize::Initialize to initialize the data source object.

When the provider persists a data source object, it persists enough information to return all of the properties in the Initialization property group to the state they were in when the data source object was persisted. The provider is not required to save the values of any properties in other property groups that the consumer has set. In most cases, this requires the provider to persist its class ID and the values of any properties set by the consumer. When the consumer loads the persisted file, the provider retrieves the persisted information and overwrites the values of any properties the consumer has set, returning them to their persisted value if they were persisted, or default value if they were not persisted.

If the provider does not support IPersistFile, the consumer can save the information necessary to re-create the data source object itself. It calls IDBProperties::GetProperties to get the value of all properties in the Initialization property group and calls IPersist::GetClassID to get the class ID of the provider. It then saves this information and later uses it to re-create the data source object.