Skip to content

Commit 231974e

Browse files
authored
Fix ExecuteUpdate returning -1 on open connections by setting NOCOUNT OFF (#37827)
Fixes #37062
1 parent 186d970 commit 231974e

45 files changed

Lines changed: 528 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ protected override Expression VisitCollate(CollateExpression collateExpression)
8080
/// </summary>
8181
protected override Expression VisitDelete(DeleteExpression deleteExpression)
8282
{
83+
Sql.Append("SET NOCOUNT OFF").AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
84+
8385
var selectExpression = deleteExpression.SelectExpression;
8486

8587
if (selectExpression is
@@ -281,6 +283,8 @@ protected override Expression VisitTableValuedFunction(TableValuedFunctionExpres
281283
/// </summary>
282284
protected override Expression VisitUpdate(UpdateExpression updateExpression)
283285
{
286+
Sql.Append("SET NOCOUNT OFF").AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
287+
284288
var selectExpression = updateExpression.SelectExpression;
285289

286290
if (selectExpression is

test/EFCore.SqlServer.FunctionalTests/BulkUpdates/Inheritance/TPCFiltersInheritanceBulkUpdatesSqlServerTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public override async Task Delete_where_hierarchy_derived(bool async)
2727

2828
AssertSql(
2929
"""
30+
SET NOCOUNT OFF;
3031
DELETE FROM [k]
3132
FROM [Kiwi] AS [k]
3233
WHERE [k].[CountryId] = 1 AND [k].[Name] = N'Great spotted kiwi'
@@ -39,6 +40,7 @@ public override async Task Delete_where_using_hierarchy(bool async)
3940

4041
AssertSql(
4142
"""
43+
SET NOCOUNT OFF;
4244
DELETE FROM [c]
4345
FROM [Countries] AS [c]
4446
WHERE (
@@ -60,6 +62,7 @@ public override async Task Delete_where_using_hierarchy_derived(bool async)
6062

6163
AssertSql(
6264
"""
65+
SET NOCOUNT OFF;
6366
DELETE FROM [c]
6467
FROM [Countries] AS [c]
6568
WHERE (
@@ -136,6 +139,7 @@ public override async Task Update_base_property_on_derived_type(bool async)
136139
"""
137140
@p='SomeOtherKiwi' (Size = 4000)
138141
142+
SET NOCOUNT OFF;
139143
UPDATE [k]
140144
SET [k].[Name] = @p
141145
FROM [Kiwi] AS [k]
@@ -151,6 +155,7 @@ public override async Task Update_derived_property_on_derived_type(bool async)
151155
"""
152156
@p='0' (Size = 1)
153157
158+
SET NOCOUNT OFF;
154159
UPDATE [k]
155160
SET [k].[FoundOn] = @p
156161
FROM [Kiwi] AS [k]
@@ -166,6 +171,7 @@ public override async Task Update_where_using_hierarchy(bool async)
166171
"""
167172
@p='Monovia' (Size = 4000)
168173
174+
SET NOCOUNT OFF;
169175
UPDATE [c]
170176
SET [c].[Name] = @p
171177
FROM [Countries] AS [c]
@@ -191,6 +197,7 @@ public override async Task Update_base_and_derived_types(bool async)
191197
@p='Kiwi' (Size = 4000)
192198
@p1='0' (Size = 1)
193199
200+
SET NOCOUNT OFF;
194201
UPDATE [k]
195202
SET [k].[Name] = @p,
196203
[k].[FoundOn] = @p1
@@ -207,6 +214,7 @@ public override async Task Update_where_using_hierarchy_derived(bool async)
207214
"""
208215
@p='Monovia' (Size = 4000)
209216
217+
SET NOCOUNT OFF;
210218
UPDATE [c]
211219
SET [c].[Name] = @p
212220
FROM [Countries] AS [c]

test/EFCore.SqlServer.FunctionalTests/BulkUpdates/Inheritance/TPCInheritanceBulkUpdatesSqlServerTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public override async Task Delete_where_hierarchy_derived(bool async)
2727

2828
AssertSql(
2929
"""
30+
SET NOCOUNT OFF;
3031
DELETE FROM [k]
3132
FROM [Kiwi] AS [k]
3233
WHERE [k].[Name] = N'Great spotted kiwi'
@@ -39,6 +40,7 @@ public override async Task Delete_where_using_hierarchy(bool async)
3940

4041
AssertSql(
4142
"""
43+
SET NOCOUNT OFF;
4244
DELETE FROM [c]
4345
FROM [Countries] AS [c]
4446
WHERE (
@@ -60,6 +62,7 @@ public override async Task Delete_where_using_hierarchy_derived(bool async)
6062

6163
AssertSql(
6264
"""
65+
SET NOCOUNT OFF;
6366
DELETE FROM [c]
6467
FROM [Countries] AS [c]
6568
WHERE (
@@ -136,6 +139,7 @@ public override async Task Update_base_property_on_derived_type(bool async)
136139
"""
137140
@p='SomeOtherKiwi' (Size = 4000)
138141
142+
SET NOCOUNT OFF;
139143
UPDATE [k]
140144
SET [k].[Name] = @p
141145
FROM [Kiwi] AS [k]
@@ -150,6 +154,7 @@ public override async Task Update_derived_property_on_derived_type(bool async)
150154
"""
151155
@p='0' (Size = 1)
152156
157+
SET NOCOUNT OFF;
153158
UPDATE [k]
154159
SET [k].[FoundOn] = @p
155160
FROM [Kiwi] AS [k]
@@ -164,6 +169,7 @@ public override async Task Update_where_using_hierarchy(bool async)
164169
"""
165170
@p='Monovia' (Size = 4000)
166171
172+
SET NOCOUNT OFF;
167173
UPDATE [c]
168174
SET [c].[Name] = @p
169175
FROM [Countries] AS [c]
@@ -189,6 +195,7 @@ public override async Task Update_base_and_derived_types(bool async)
189195
@p='Kiwi' (Size = 4000)
190196
@p1='0' (Size = 1)
191197
198+
SET NOCOUNT OFF;
192199
UPDATE [k]
193200
SET [k].[Name] = @p,
194201
[k].[FoundOn] = @p1
@@ -204,6 +211,7 @@ public override async Task Update_where_using_hierarchy_derived(bool async)
204211
"""
205212
@p='Monovia' (Size = 4000)
206213
214+
SET NOCOUNT OFF;
207215
UPDATE [c]
208216
SET [c].[Name] = @p
209217
FROM [Countries] AS [c]
@@ -225,6 +233,7 @@ public override async Task Update_with_interface_in_property_expression(bool asy
225233
"""
226234
@p='0'
227235
236+
SET NOCOUNT OFF;
228237
UPDATE [c]
229238
SET [c].[SugarGrams] = @p
230239
FROM [Coke] AS [c]
@@ -239,6 +248,7 @@ public override async Task Update_with_interface_in_EF_Property_in_property_expr
239248
"""
240249
@p='0'
241250
251+
SET NOCOUNT OFF;
242252
UPDATE [c]
243253
SET [c].[SugarGrams] = @p
244254
FROM [Coke] AS [c]

test/EFCore.SqlServer.FunctionalTests/BulkUpdates/Inheritance/TPHFiltersInheritanceBulkUpdatesSqlServerTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public override async Task Delete_where_hierarchy(bool async)
2121

2222
AssertSql(
2323
"""
24+
SET NOCOUNT OFF;
2425
DELETE FROM [a]
2526
FROM [Animals] AS [a]
2627
WHERE [a].[CountryId] = 1 AND [a].[Name] = N'Great spotted kiwi'
@@ -33,6 +34,7 @@ public override async Task Delete_where_hierarchy_derived(bool async)
3334

3435
AssertSql(
3536
"""
37+
SET NOCOUNT OFF;
3638
DELETE FROM [a]
3739
FROM [Animals] AS [a]
3840
WHERE [a].[Discriminator] = N'Kiwi' AND [a].[CountryId] = 1 AND [a].[Name] = N'Great spotted kiwi'
@@ -45,6 +47,7 @@ public override async Task Delete_where_using_hierarchy(bool async)
4547

4648
AssertSql(
4749
"""
50+
SET NOCOUNT OFF;
4851
DELETE FROM [c]
4952
FROM [Countries] AS [c]
5053
WHERE (
@@ -60,6 +63,7 @@ public override async Task Delete_where_using_hierarchy_derived(bool async)
6063

6164
AssertSql(
6265
"""
66+
SET NOCOUNT OFF;
6367
DELETE FROM [c]
6468
FROM [Countries] AS [c]
6569
WHERE (
@@ -89,6 +93,7 @@ public override async Task Delete_GroupBy_Where_Select_First_3(bool async)
8993

9094
AssertSql(
9195
"""
96+
SET NOCOUNT OFF;
9297
DELETE FROM [a]
9398
FROM [Animals] AS [a]
9499
WHERE [a].[CountryId] = 1 AND [a].[Id] IN (
@@ -120,6 +125,7 @@ public override async Task Delete_where_hierarchy_subquery(bool async)
120125
@p='0'
121126
@p1='3'
122127
128+
SET NOCOUNT OFF;
123129
DELETE FROM [a]
124130
FROM [Animals] AS [a]
125131
WHERE [a].[Id] IN (
@@ -140,6 +146,7 @@ public override async Task Update_base_type(bool async)
140146
"""
141147
@p='Animal' (Size = 4000)
142148
149+
SET NOCOUNT OFF;
143150
UPDATE [a]
144151
SET [a].[Name] = @p
145152
FROM [Animals] AS [a]
@@ -155,6 +162,7 @@ public override async Task Update_base_type_with_OfType(bool async)
155162
"""
156163
@p='NewBird' (Size = 4000)
157164
165+
SET NOCOUNT OFF;
158166
UPDATE [a]
159167
SET [a].[Name] = @p
160168
FROM [Animals] AS [a]
@@ -177,6 +185,7 @@ public override async Task Update_base_property_on_derived_type(bool async)
177185
"""
178186
@p='SomeOtherKiwi' (Size = 4000)
179187
188+
SET NOCOUNT OFF;
180189
UPDATE [a]
181190
SET [a].[Name] = @p
182191
FROM [Animals] AS [a]
@@ -192,6 +201,7 @@ public override async Task Update_derived_property_on_derived_type(bool async)
192201
"""
193202
@p='0' (Size = 1)
194203
204+
SET NOCOUNT OFF;
195205
UPDATE [a]
196206
SET [a].[FoundOn] = @p
197207
FROM [Animals] AS [a]
@@ -208,6 +218,7 @@ public override async Task Update_base_and_derived_types(bool async)
208218
@p='Kiwi' (Size = 4000)
209219
@p1='0' (Size = 1)
210220
221+
SET NOCOUNT OFF;
211222
UPDATE [a]
212223
SET [a].[Name] = @p,
213224
[a].[FoundOn] = @p1
@@ -224,6 +235,7 @@ public override async Task Update_where_using_hierarchy(bool async)
224235
"""
225236
@p='Monovia' (Size = 4000)
226237
238+
SET NOCOUNT OFF;
227239
UPDATE [c]
228240
SET [c].[Name] = @p
229241
FROM [Countries] AS [c]
@@ -242,6 +254,7 @@ public override async Task Update_where_using_hierarchy_derived(bool async)
242254
"""
243255
@p='Monovia' (Size = 4000)
244256
257+
SET NOCOUNT OFF;
245258
UPDATE [c]
246259
SET [c].[Name] = @p
247260
FROM [Countries] AS [c]

test/EFCore.SqlServer.FunctionalTests/BulkUpdates/Inheritance/TPHInheritanceBulkUpdatesSqlServerTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public override async Task Delete_where_hierarchy(bool async)
2020

2121
AssertSql(
2222
"""
23+
SET NOCOUNT OFF;
2324
DELETE FROM [a]
2425
FROM [Animals] AS [a]
2526
WHERE [a].[Name] = N'Great spotted kiwi'
@@ -32,6 +33,7 @@ public override async Task Delete_where_hierarchy_derived(bool async)
3233

3334
AssertSql(
3435
"""
36+
SET NOCOUNT OFF;
3537
DELETE FROM [a]
3638
FROM [Animals] AS [a]
3739
WHERE [a].[Discriminator] = N'Kiwi' AND [a].[Name] = N'Great spotted kiwi'
@@ -44,6 +46,7 @@ public override async Task Delete_where_using_hierarchy(bool async)
4446

4547
AssertSql(
4648
"""
49+
SET NOCOUNT OFF;
4750
DELETE FROM [c]
4851
FROM [Countries] AS [c]
4952
WHERE (
@@ -59,6 +62,7 @@ public override async Task Delete_where_using_hierarchy_derived(bool async)
5962

6063
AssertSql(
6164
"""
65+
SET NOCOUNT OFF;
6266
DELETE FROM [c]
6367
FROM [Countries] AS [c]
6468
WHERE (
@@ -88,6 +92,7 @@ public override async Task Delete_GroupBy_Where_Select_First_3(bool async)
8892

8993
AssertSql(
9094
"""
95+
SET NOCOUNT OFF;
9196
DELETE FROM [a]
9297
FROM [Animals] AS [a]
9398
WHERE [a].[Id] IN (
@@ -118,6 +123,7 @@ public override async Task Delete_where_hierarchy_subquery(bool async)
118123
@p='0'
119124
@p1='3'
120125
126+
SET NOCOUNT OFF;
121127
DELETE FROM [a]
122128
FROM [Animals] AS [a]
123129
WHERE [a].[Id] IN (
@@ -138,6 +144,7 @@ public override async Task Update_base_type(bool async)
138144
"""
139145
@p='Animal' (Size = 4000)
140146
147+
SET NOCOUNT OFF;
141148
UPDATE [a]
142149
SET [a].[Name] = @p
143150
FROM [Animals] AS [a]
@@ -153,6 +160,7 @@ public override async Task Update_base_type_with_OfType(bool async)
153160
"""
154161
@p='NewBird' (Size = 4000)
155162
163+
SET NOCOUNT OFF;
156164
UPDATE [a]
157165
SET [a].[Name] = @p
158166
FROM [Animals] AS [a]
@@ -175,6 +183,7 @@ public override async Task Update_base_property_on_derived_type(bool async)
175183
"""
176184
@p='SomeOtherKiwi' (Size = 4000)
177185
186+
SET NOCOUNT OFF;
178187
UPDATE [a]
179188
SET [a].[Name] = @p
180189
FROM [Animals] AS [a]
@@ -190,6 +199,7 @@ public override async Task Update_derived_property_on_derived_type(bool async)
190199
"""
191200
@p='0' (Size = 1)
192201
202+
SET NOCOUNT OFF;
193203
UPDATE [a]
194204
SET [a].[FoundOn] = @p
195205
FROM [Animals] AS [a]
@@ -205,6 +215,7 @@ public override async Task Update_where_using_hierarchy(bool async)
205215
"""
206216
@p='Monovia' (Size = 4000)
207217
218+
SET NOCOUNT OFF;
208219
UPDATE [c]
209220
SET [c].[Name] = @p
210221
FROM [Countries] AS [c]
@@ -224,6 +235,7 @@ public override async Task Update_base_and_derived_types(bool async)
224235
@p='Kiwi' (Size = 4000)
225236
@p1='0' (Size = 1)
226237
238+
SET NOCOUNT OFF;
227239
UPDATE [a]
228240
SET [a].[Name] = @p,
229241
[a].[FoundOn] = @p1
@@ -240,6 +252,7 @@ public override async Task Update_where_using_hierarchy_derived(bool async)
240252
"""
241253
@p='Monovia' (Size = 4000)
242254
255+
SET NOCOUNT OFF;
243256
UPDATE [c]
244257
SET [c].[Name] = @p
245258
FROM [Countries] AS [c]
@@ -265,6 +278,7 @@ public override async Task Update_with_interface_in_property_expression(bool asy
265278
"""
266279
@p='0'
267280
281+
SET NOCOUNT OFF;
268282
UPDATE [d]
269283
SET [d].[SugarGrams] = @p
270284
FROM [Drinks] AS [d]
@@ -280,6 +294,7 @@ public override async Task Update_with_interface_in_EF_Property_in_property_expr
280294
"""
281295
@p='0'
282296
297+
SET NOCOUNT OFF;
283298
UPDATE [d]
284299
SET [d].[SugarGrams] = @p
285300
FROM [Drinks] AS [d]

0 commit comments

Comments
 (0)