C# Set CommandTimeout manually when using auto-generated typed datasets

I couldn’t find a way to increase the default command timeout quickly without having to do something complicated so I had to open up my .Designer.cs file (maintained by Visual Studio IDE), find the Fill method I was looking for and look for this line:

this.Adapter.SelectCommand = this.CommandCollection[0];

Then I manually set my command timeout like this:

this.CommandCollection[0].CommandTimeout = 300; //your command timeout in seconds.
this.Adapter.SelectCommand = this.CommandCollection[0];

Not the most elegant solution, but a good enough emergency fix.
Keep in mind you’ll have to re-add this line when you regenerate your typed dataset from your stored procedure or function.

Leave a Reply