Skip to content

Commit 560d2c6

Browse files
.
1 parent 8ee7c01 commit 560d2c6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/SqlDataAdapterBatchUpdateTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,15 @@ internal void TruncateTables(string tableName, string connectionString)
173173
{
174174
using var connection = new SqlConnection(GetOpenConnectionString(connectionString, encryptionEnabled: true));
175175
connection.Open();
176-
SilentRunCommand($@"TRUNCATE TABLE [dbo].[{tableNames[tableName]}]", connection);
176+
try
177+
{
178+
SilentRunCommand($@"TRUNCATE TABLE [dbo].[{tableNames[tableName]}]", connection);
179+
}
180+
catch
181+
{
182+
// Fallback to DELETE if TRUNCATE fails (e.g., due to FK constraints)
183+
SilentRunCommand($@"DELETE FROM [dbo].[{tableNames[tableName]}]", connection);
184+
}
177185
}
178186

179187
internal void ExecuteQuery(SqlConnection connection, string commandText)

0 commit comments

Comments
 (0)