Greetings! One of the topics I covered during my presentation on Data Access Techniques with Sitecore CMS

The idea behind the scenes is to separate the Link Database used on the Content Delivery side from the one used on the Content Management side by introducing a second link database. This database will be updated during item publishing. This way if CMS decides to update its own Link DB, the one used on the front-end will not be affected.

So, here is what you need to do:

  1. Add the FrontEndLinkDatabase definition below the default <LinkDatabase> in web.config file of the CMS server:
<!-- LINK DATABASE -->
<LinkDatabase type="Sitecore.Data.$(database).$(database)LinkDatabase,
 Sitecore.Kernel">  
 <param connectionStringName="core" />  
</LinkDatabase>  
<!-- FRONT END LINK DATABASE -->  
<FrontEndLinkDatabase type="Sitecore.Data.$(database).$(database)LinkDatabase,  
 Sitecore.$(database)">  
 <param desc="connection" ref="connections/web" />  
</FrontEndLinkDatabase>  
  1. Compile the following code that contains two Sitecore event handlers (publish:itemprocessed and publish:itemprocessing)
using System;
using Sitecore.Configuration;
using Sitecore.Links;  
using Sitecore.Publishing;  
using Sitecore.Publishing.Pipelines.PublishItem;  
using Sitecore.Diagnostics;  
namespace Sitecore.SharedSource.LinkDatabaseRebuilder  
{  
 public class EventHandler  
 {  
 protected static LinkDatabase FrontEndLinkDatabase  
 {  
 get  
 {  
 return (Factory.CreateObject("FrontEndLinkDatabase", true)  
 as LinkDatabase);  
 }  
 }  
 public string Database { get; set; }  
 public void OnItemProcessed(object sender, EventArgs args)  
 {  
 var context = ((ItemProcessedEventArgs)args).Context;  
 Assert.IsNotNull(context,  
 "Cannot get PublishItem context");  
 Assert.IsNotNull(FrontEndLinkDatabase,  
 "Cannot resolve FrontEndLinkDatabase from config");  
 if (context.PublishOptions.TargetDatabase.Name.Equals(Database))  
 {  
 var item = context.PublishHelper.GetTargetItem(context.ItemId);  
 // if an item was not unpublished,  
 // the call below will reintroduce the reference  
 // removed within OnItemProcessing method  
 if (item != null)  
 {  
 FrontEndLinkDatabase.UpdateReferences(item);  
 }  
 }  
 }  
 public void OnItemProcessing(object sender, EventArgs args)  
 {  
 var context = ((ItemProcessingEventArgs)args).Context;  
 Assert.IsNotNull(context,  
 "Cannot get PublishItem context");  
 Assert.IsNotNull(FrontEndLinkDatabase,  
 "Cannot resolve FrontEndLinkDatabase from config");  
 if (context.PublishOptions.TargetDatabase.Name.Equals(Database))  
 {  
 if (context.Action == PublishAction.DeleteTargetItem)  
 {  
 var item = context.PublishHelper.GetTargetItem(context.ItemId);  
 Assert.IsNotNull(item, "Source item cannot be found");  
 FrontEndLinkDatabase.RemoveReferences(item);  
 }  
 }  
 }  
 }  
}
  1. Last thing to do is to define the two event handler mapping in web.config.
<events>
 <event name="publish:itemProcessing">
 <handler type="Sitecore.SharedSource.LinkDatabaseRebuilder.EventHandler, 

Sitecore.SharedSource.LinkDatabaseRebuilder" method="OnItemProcessing">  
 <database>web</database>  
 </handler>  
 </event>  
 <event name="publish:itemProcessed">  
 <handler type="Sitecore.SharedSource.LinkDatabaseRebuilder.EventHandler, 

Sitecore.SharedSource.LinkDatabaseRebuilder" method="OnItemProcessed">  
 <database>web</database>  
 </handler>  
 </event>  
 </events>  

That’s all you need to do. For the sake of simplicity, here is the link

While this solution has been tested on 6.2, it is expected to work on all Sitecore 6 installations.

Let me know if it does not ;-)