How to Purge Old Marketing Data
Periodically, you may have to remove expired marketing data from your installation.
Marketing data is marked as archived instead of being physically removed when it is deleted by using the marketing management API. This enables a database administrator to recover accidentally deleted data.
Database administrators can periodically purge the old data from the marketing database using the DataManager object.
To Purge Old Marketing Data
Define the number of days of data that you want to delete.
Connect a DataManager object to the Marketing databases.
Purge Promotion Code data that was created before the specified number of days before today.
Purge Campaign item data that was created before the specified number of days before today.
Purge Campaign data that was created before the specified number of days before today.
Purge Customer data that was created before the specified number of days before today.
Example
You can view the results in the Marketing Manager.
using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Marketing;
namespace CommerceServerMarketingExamples
{
public class CSMarketingExamples
{
public void PurgeMarketingData()
{
try
{
// Purge 60 days of Promotion Code data.
int ageOutDays = 60;
// Purge 90 days of Campaign, Campaign Item, and Customer data.
int daysSinceDeletion = 90;
DataManager manager = new DataManager("Data Source=(local);Initial Catalog=StarterSite_marketing;Integrated Security=SSPI", "Data Source=(local);Initial Catalog=StarterSite_marketing_lists;Integrated Security=SSPI");
manager.PurgeOldPromoCodes(ageOutDays, PromoCodePurgeOption.CodesForExpiredDiscountsAndDeletedDiscounts);
manager.PurgeDeletedCampaignItems(daysSinceDeletion);
manager.PurgeDeletedCampaigns(daysSinceDeletion);
manager.PurgeDeletedCustomers(daysSinceDeletion);
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}\r\nMessage: {1} " + ex.GetType() + " " + ex.Message);
if (ex.InnerException != null)
Console.WriteLine("\r\nInner Exception: {0}\r\nMessage: {1}" + ex.InnerException.GetType() + ex.InnerException.Message);
Console.WriteLine("\n");
}
}
}