RE: How to set commandTimeout for ObjectDataSource
Piotrek said:
HI all.
In my web site I have some ObjetDataSource. Its business object
property is set to my dataset I created in dataset designer (this
dataset has table adapter).
My question is: how can I set command time-out property for fill method
from this table adapter?
Thanks in advance,
Piotrek.
Here is your answer:
1. Open your Dataset (lets say
MyDataSet.xsd file).
2. Double click on your table adapter (lets say
MyTableAdapter)
Visual Studio will switch you to
MyDataSet.cs file and will generate similar code for you:
Code:
namespace Company.Project.DataProvider {
partial class MyDataSet
{
partial class MyDataTable
{
}
}
}
3. Now you need to add new property which will help to set command time-out for all commands controller by
MyTableAdapter:
Code:
[COLOR="Silver"]namespace Company.Project.DataProvider {
partial class MyDataSet
{
partial class MyDataTable
{
}
}
}[/COLOR]
namespace Company.Project.DataProvider.MyDataSetTableAdapters
{
public partial class MyTableAdapter
{
public int CommandTimeout
{
set
{
for (int i = 0; (i < this.CommandCollection.Length); i = (i + 1))
{
if ((this.CommandCollection[i] != null))
{
this.CommandCollection[i].CommandTimeout = value;
}
}
}
}
}
}
4. Open ASPX page where you are using ObjetDataSource (lets say
MyObjetDataSource
5. Select
MyObjetDataSource, click with right-mouse on it and from menu choose
Properties
6. Visual studio will open Properties window for
MyObjetDataSource
On top of all properties list there is toolbar. Click lightning icon to see all events of
MyObjetDataSource.
7. Double click on
ObjectCreated event
8. Visual Studio will open source code of ASPX page and will generate event function for you:
Code:
protected void MyDataSource_ObjectCreated(object sender, ObjectDataSourceEventArgs e)
{
}
9. Create code which will set Command Timeout just after
MyDataSource has been created created
Code:
[COLOR="Silver"]protected void MyDataSource_ObjectCreated(object sender, ObjectDataSourceEventArgs e)
{[/COLOR]
Company.Project.DataProvider.MyDataSetTableAdapters.MyTableAdapter adapter;
adapter = (Company.Project.DataProvider.MyDataSetTableAdapters.MyTableAdapter)e.ObjectInstance;
// Set command timeout to 2 minutes
adapter.CommandTimeout = 120;
[COLOR="Silver"]}[/COLOR]
Done.
Keywords: C#, commandTimeout, ObjectDataSource, DataSet, TableAdapter, Designer, Solution, Code Example, Resolved,
www.jocys.com