I recently had an issue with command timeouts with an EPiServer Community site. The community database is quite large and I had a batch import job that added new entities. During some large maintaince queries on the database that results in locking of the tables, some timeouts occurred in that period. The Community API uses the default timeout which is 30 seconds and there is no buildt in way of changing this with some sort of configuration. To overcome this issue I added the following fix.
EPiServer Community 4.0 uses the DatabaseHandler, located in the common framework. I was somewhat surprised to see that this class has both a public instance property as well as public virtual methods. One of these methods is the GetCommand method which have overriden with the following code.
public class MyDatabaseHandler : EPiServer.Common.Data.DatabaseHandler
{
public override System.Data.Common.DbCommand GetCommand(bool inTransaction,
string sp,
System.Data.CommandType commandType,
params object[] args)
{
var command = base.GetCommand(inTransaction, sp, commandType, args);
command.CommandTimeout = 1800;
return command;
}
}
Then simply create a EPiServer Community module that instanciates and sets the current DatabaseHandler to our custom db handler.
public class DatabaseModule : IModule
{
public string UniqueName
{
get { return Name; }
}
public string AdministrationControl
{
get { return ""; }
}
public string Name
{
get { return "RelatePlusDatabaseModule"; }
}
public void OnApplicationStart(CommunityContext context)
{
EPiServer.Common.Data.DatabaseHandler.Instance = new MyDatabaseHandler();
}
}