Monday, August 8, 2011

Timeout Elapsed

We Got a issue for one of our application which has webparts on MOSS. This webpart has a search control and search results are displayed in Grid.

When search is performed then no results are displayed and we are getting
"Timeout expired. The timeout period elapsed prior to completion ofthe operation or the server is not responding."
After investigating we found our Table adpater is failing so to fix we wrote a small utility/added property  within the Tableadpater partial class.
And assigned commandTimeout property to the table adapter when before making call to DB.

Please find below code
namespace xxxTableAdapters
{

public partial class yyyTableAdapter

{

public int CommandTimeout {

set {

int i = 0;

while ((i < this.CommandCollection.Length)) {

if ((this.CommandCollection(i) != null)) {

this.CommandCollection(i).CommandTimeout = value;
}
i = (i + 1);
}

}
}

}

}
Assign property
public static DataTable GetSearchListt(int year, int month,string companyGroup)
{
DataTable result = null;
using (MyDataTableAdapters.DataTableAdapter tableAdapter = new MyDataTableAdapters.DataTableAdapter())
{
tableAdapter.CommandTimeout = 4000;
result = tableAdapter.GetData(year, month,Group);
}
return result
}

Let me know if it helped any one
Cheers :)

No comments: