API Questions on Kentico API.
Version 6.x > API > Custom Data Source in Kentico 6 View modes: 
User avatar
Member
Member
John-CymbalInteractive - 10/26/2011 6:39:46 PM
   
Custom Data Source in Kentico 6
Hi,

I have spent today updating to Kentico 6 and I have run into an issue with a custom data source I created for 5.5r2. For some reason this web part no longer works and causes my app pool to die. I have tried debugging using remote debug to our dev server but it won't load the source files. It looks like my code is causing a stack overflow. Anyway, here is the source.


using System;
using CMS.CMSHelper;
using CMS.Community;
using CMS.Controls;
using CMS.DataEngine;
using CMS.SettingsProvider;
using CMS.SiteProvider;

public partial class CMSWebParts_DataSources_PeopleYouMayKnowDataSource : CMSBaseDataSource
{
#region "Variables"

private string mWhereCondition = String.Empty;
private string mOrderBy = String.Empty;

#endregion


#region "Properties"

/// <summary>
/// Gets or sets the where condition
/// </summary>
public string WhereCondition
{
get
{
return mWhereCondition;
}
set
{
mWhereCondition = value;
}
}


/// <summary>
/// Gets the data source
/// </summary>
public override object DataSource
{
get
{
return base.GetDataSource();
}
}

/// <summary>
/// Gets or sets the order by clause
/// </summary>
public string OrderBy
{
get
{
return mOrderBy;
}
set
{
mOrderBy = value;
}
}

#endregion


#region "Methods"

/// <summary>
/// Handle filter change event
/// </summary>
protected override void OnInit(EventArgs e)
{
if (SourceFilterControl != null)
{
SourceFilterControl.OnFilterChanged += new ActionEventHandler(DataFilter_OnFilterChanged);
}

base.OnInit(e);
}


/// <summary>
/// OnFilterChange handler
/// </summary>
void DataFilter_OnFilterChanged()
{
// Clear old data
InvalidateLoadedData();
// Raise change event
this.RaiseOnFilterChanged();
}

protected override object GetDataSourceFromDB()
{
if (base.DataSource != null)
{
return base.DataSource;
}

GeneralConnection cn = ConnectionHelper.GetConnection();

if (!string.IsNullOrEmpty(WhereCondition))
{
WhereCondition = " and " + WhereCondition;
}

var qdp = new QueryDataParameters();
qdp.Add("@UserID", CMSContext.CurrentUser.UserID);

base.DataSource = cn.ExecuteQuery("cms.user.peopleyoumayknow", qdp, WhereCondition, OrderBy, TopN, SelectedColumns);
cn.Close();

return base.DataSource;
}

#endregion
}


Thanks,
John

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 11/7/2011 3:20:33 AM
   
RE:Custom Data Source in Kentico 6
Hi,

thank you for letting us know about this issue. It is a bug in the documentation. The correct data source control should contain:


/// <summary>
/// Gets the data source
/// </summary>

public override object DataSource
{

// replace your content with this
get
{
return mDataSource ?? (mDataSource = this.GetDataSource());
}
set
{
this.mDataSource = (DataSet)value;
}
}



and


/// <summary>
/// Gets the datasource data
/// </summary>

protected override object GetDataSourceFromDB()
{
// remove check for null

// Initialize properties with dependence on filter settings
if (SourceFilterControl != null)
{
SourceFilterControl.InitDataProperties(this);
}

// Load data, in this example nothing is loaded

base.DataSource = UserInfoProvider.GetFullUsers(this.WhereCondition, this.OrderBy);
return base.DataSource;
}


The original version of control creates a cycle and the application pool crashed.

With this change the control should work correctly.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
John-CymbalInteractive - 11/7/2011 11:05:59 AM
   
RE:Custom Data Source in Kentico 6
Thanks Ivana.

I ended up figuring it out myself by removing the null check. I remembered that I had to set the web.config to debug again since I updated my site from 5.5 to 6. Everything is going well now.

John