0

I discovered that since NHibernate 5.0 I can call the following code to delete all records of a table:

session.Query<T>().Delete();

It executes the code on the database without copying it across the network, which should improve performance a lot. But this query times out.

I get the following error:

Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

I've tried setting the Connection Timeout setting in my connectionstring to 0 and to 3600, but it makes no difference.

My table only has about 200 records. But one column is a base64 encoded pdf, so it is quite big and the query would take a few seconds.

What else can I try?

Quintonn
  • 770
  • 8
  • 29
  • 1
    I've managed to get past this error for now using session.Query().Timeout(600).Delete();. But i feel like this is a temporary work-around. I would appreciate a better explanation/understanding of why this is needed. – Quintonn Apr 14 '18 at 09:07
  • Have you taken a look at your database (SQL Server?) activity in isolation? For example, if you run the query `DELETE FROM MyTable WHERE MyColumn = 1;` (or whatever the correct query is) what's the performance like? Is there any contention on that table that's causing the `DELETE` to be blocked? – David Osborne Apr 16 '18 at 09:15

1 Answers1

0

It sounds like you need to increase the command timeout.

Note that there is a difference between connection timeout and command timeout.

You can set the default command timeout (in seconds) for ADO.NET commands created by NHibernate using the command_timeout NHibernate session configuration property. There are multiple ways to do that depending on what method you use to configure NHibernate. Here are the basics: http://nhibernate.info/doc/nhibernate-reference/session-configuration.html

Oskar Berggren
  • 5,583
  • 1
  • 19
  • 36