23

I have recently started using LinqPad, and bought the Autocomplete option and am really loving it. This is an excellent product!

I wanted to ask if there is a way for me to control the command timeout that used when querying a SQL Server database in LinqPAD (I am using c# statements)? I can't see where we have access to the actual connection string, and I have some large queries for reporting that are timing out. It appears that the timeout is hard-coded at 30 seconds.

Thanks in advance for any help!

Yahoo Serious
  • 3,728
  • 1
  • 33
  • 37
blairh
  • 243
  • 2
  • 5

3 Answers3

19

I have run queries that have taken minutes and never had a command time out. That said, here's how you change it...


All of the work you perform inside a UserQuery. The CommandTimeout is a property of that.

this.CommandTimeout = 60;

Have a look at all the properties under this. It gives you a nice insight into some of the things you can do.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
  • 1
    THANK YOU! (Especially for the near-immediate response! (kicking myself for not having checked out 'this'!) (given that I do it a million times a day on my own code!) Anyway, it worked perfectly! – blairh Dec 09 '11 at 16:57
  • It's a nice feature, I not sure why it isn't documented better. – DaveShaw Dec 09 '11 at 16:59
  • @user1090088 - Would you mind accepting the answer in keeping with the SO style: http://stackoverflow.com/faq#howtoask ? Thanks. – DaveShaw Dec 09 '11 at 17:27
  • 1
    By default, LINQPad sets the command timeout to infinite. If you're getting timeout errors, I would suspect it's either the connection (rather than the command) that's timing out, or the timeout is to do with the network or server. – Joe Albahari Dec 10 '11 at 05:28
  • 1
    @Joe Albahari, I do get time-outs when/if [LinqPad connects to DB using an EF-library](http://www.linqpad.net/entityframework.aspx). Is there a way to set a/the default time-out to infinite for EF-libraries. ([My answer](http://stackoverflow.com/a/15543838/422877) already shows an ad hoc way for the command window.) – Yahoo Serious Apr 04 '13 at 12:26
15

As mentioned in @DaveShaw's answer when querying a SQL Server database in LinqPAD using a 'regular' connection, you can use:

this.CommandTimeout = 60

However, this property is not available when LinqPad connects to DB using an EF-library. Using this.CommandTimeout results in:

'UserQuery' does not contain a definition for 'CommandTimeout' and no extension method 'CommandTimeout' accepting a first argument of type 'UserQuery' could be found (press F4 to add a using directive or assembly reference)

Some puzzling and a this answer about EF time-outs in general led me to use this on an EF-connection:

(this as IObjectContextAdapter).ObjectContext.CommandTimeout = 60;
Community
  • 1
  • 1
Yahoo Serious
  • 3,728
  • 1
  • 33
  • 37
5

For Entity Framework Core connections used the following property instead.
this.Database.SetCommandTimeout(120);

Adrian
  • 3,332
  • 5
  • 34
  • 52