Skip to content

Commit 4691a43

Browse files
author
Davy Brion
committed
Fix NH-1913
SVN: trunk@4684
1 parent 6867ec4 commit 4691a43

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/NHibernate/AdoNet/SqlClientBatchingBatcher.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Data;
22
using System.Text;
33
using NHibernate.AdoNet.Util;
4+
using NHibernate.Util;
45

56
namespace NHibernate.AdoNet
67
{
@@ -21,13 +22,34 @@ public SqlClientBatchingBatcher(ConnectionManager connectionManager, IIntercepto
2122
{
2223
batchSize = Factory.Settings.AdoBatchSize;
2324
currentBatch = new SqlClientSqlCommandSet();
25+
SetCommandTimeout();
2426
//we always create this, because we need to deal with a scenario in which
2527
//the user change the logging configuration at runtime. Trying to put this
2628
//behind an if(log.IsDebugEnabled) will cause a null reference exception
2729
//at that point.
2830
currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:");
2931
}
3032

33+
private void SetCommandTimeout()
34+
{
35+
int timeout = PropertiesHelper.GetInt32(Cfg.Environment.CommandTimeout, Cfg.Environment.Properties, -1);
36+
37+
if (timeout > 0)
38+
{
39+
try
40+
{
41+
currentBatch.CommandTimeout = timeout;
42+
}
43+
catch (Exception e)
44+
{
45+
if (log.IsWarnEnabled)
46+
{
47+
log.Warn(e.ToString());
48+
}
49+
}
50+
}
51+
}
52+
3153
public override int BatchSize
3254
{
3355
get { return batchSize; }

src/NHibernate/AdoNet/SqlClientSqlCommandSet.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class SqlClientSqlCommandSet : IDisposable
1818
private object instance;
1919
private PropSetter<SqlConnection> connectionSetter;
2020
private PropSetter<SqlTransaction> transactionSetter;
21+
private PropSetter<int> commandTimeoutSetter;
2122
private PropGetter<SqlConnection> connectionGetter;
2223
private SqlClientSqlCommandSet.PropGetter<System.Data.SqlClient.SqlCommand> commandGetter;
2324
private AppendCommand doAppend;
@@ -41,6 +42,9 @@ public SqlClientSqlCommandSet()
4142
transactionSetter = (PropSetter<SqlTransaction>)
4243
Delegate.CreateDelegate(typeof(PropSetter<SqlTransaction>),
4344
instance, "set_Transaction");
45+
commandTimeoutSetter = (PropSetter<int>)
46+
Delegate.CreateDelegate(typeof(PropSetter<int>),
47+
instance, "set_CommandTimeout");
4448
connectionGetter = (PropGetter<SqlConnection>)
4549
Delegate.CreateDelegate(typeof(PropGetter<SqlConnection>),
4650
instance, "get_Connection");
@@ -130,6 +134,11 @@ public SqlTransaction Transaction
130134
set { transactionSetter(value); }
131135
}
132136

137+
public int CommandTimeout
138+
{
139+
set { commandTimeoutSetter(value); }
140+
}
141+
133142
///<summary>
134143
///Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
135144
///</summary>

0 commit comments

Comments
 (0)