@@ -19,7 +19,7 @@ namespace NHibernate.AdoNet
19
19
/// </summary>
20
20
public partial class GenericBatchingBatcher : AbstractBatcher
21
21
{
22
- private readonly int _maxNumberOfParameters = int . MaxValue ;
22
+ private readonly int ? _maxNumberOfParameters ;
23
23
private readonly BatchingCommandSet _currentBatch ;
24
24
private int _totalExpectedRowsAffected ;
25
25
private StringBuilder _currentBatchCommandsLog ;
@@ -30,14 +30,8 @@ public GenericBatchingBatcher(ConnectionManager connectionManager, IInterceptor
30
30
BatchSize = Factory . Settings . AdoBatchSize ;
31
31
StatementTerminator = statementTerminator ;
32
32
_currentBatch = new BatchingCommandSet ( this ) ;
33
- // On Sql Server there is a limit of 2100 parameters, but 2 are reserved for sp_executesql, so
34
- // we are able to use up to 2098 parameters. When sp_prepexec is used for preparing and executing
35
- // statements then one more parameter is used. Set the max number of parameters to 2097 in order
36
- // to ensure that we will never exceed the limit.
37
- if ( Factory . Dialect is MsSql2000Dialect )
38
- {
39
- _maxNumberOfParameters = 2097 ;
40
- }
33
+ _maxNumberOfParameters = Factory . Dialect . MaxNumberOfParameters ;
34
+
41
35
// We always create this, because we need to deal with a scenario in which
42
36
// the user change the logging configuration at runtime. Trying to put this
43
37
// behind an if(log.IsDebugEnabled) will cause a null reference exception
@@ -54,7 +48,8 @@ public GenericBatchingBatcher(ConnectionManager connectionManager, IInterceptor
54
48
public override void AddToBatch ( IExpectation expectation )
55
49
{
56
50
var batchUpdate = CurrentCommand ;
57
- if ( _currentBatch . CountOfParameters + CurrentCommand . Parameters . Count > _maxNumberOfParameters )
51
+ if ( _maxNumberOfParameters . HasValue &&
52
+ _currentBatch . CountOfParameters + CurrentCommand . Parameters . Count > _maxNumberOfParameters )
58
53
{
59
54
ExecuteBatchWithTiming ( batchUpdate ) ;
60
55
}
0 commit comments