Welcome...



...All those moments will be lost in time, like tears in rain....

- soliloquy from Blade Runner


Bits and bytes do get lost, awash in the rain of data flow that is Internet. They slip away from us, never to found again... some of them will be captured here, many more will not... like tears in rain...



Monday, January 14, 2013

Datasets and timeouts

When using tableadapter to retrieve the data from database, Microsoft did not provide property to set command timeout anywhere, unless you go to generated file directly.
 Once in XDataSet.Designer.cs file, there are 2 places that Command Timeout can be set:
1) On SelectCommand of Adapter itself  - if this is for data retrieval calls, GetData method:
this.Adapter.SelectCommand.CommandTimeout = 60;
2) On initialization of command collection - each stored procedure call can have it's own command timeout.
 this._commandCollection[0].CommandTimeout = 60;

 By default, no timeout is set, and default is 30 seconds.


2 comments:

  1. Nice pointer! Take care when editing a generated file - it might be a good idea to add a search/replace as a post-build step, or to use reflection from outside the generated code to get at the private _commandCollection member and set the timeout.

    ReplyDelete
  2. Actually, turned out that there is a way to do it in the code behind of DataSet file, by using adapters.
    Something like this:

    partial class MyDataTable
    {
    public static MyDataTable Load(Criteria criteria)
    {
    MyTableAdapter adapter = DataSqlAdaptersFactory.GetAdapter();

    adapter.PublicCommandCollection[0].CommandTimeout = 0;

    return adapter.LoadData(criteria);
    }
    } ...

    ReplyDelete