Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set Command Timeout in Linqpad?

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!

like image 659
blairh Avatar asked Dec 09 '11 16:12

blairh


People also ask

How do I change the command timeout in SQL?

Select Query Execution from tree on left side and enter command timeout in "Execute Timeout" control. Changing Command Timeout in Server: In the object browser tree right click on the server which give you timeout and select "Properties" from context menu. you can set the value in up/down control.

What is the default SQL command timeout?

Gets or sets the wait time (in seconds) before terminating the attempt to execute a command and generating an error. The default is 30 seconds.


3 Answers

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.

like image 89
DaveShaw Avatar answered Sep 29 '22 08:09

DaveShaw


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;
like image 25
Yahoo Serious Avatar answered Sep 29 '22 06:09

Yahoo Serious


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

like image 32
Adrian Avatar answered Sep 29 '22 08:09

Adrian