diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs index 9eda28368f..ec9fe6c45c 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/Runner.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Linq; namespace Microsoft.Data.SqlClient.ExtUtilities { @@ -16,9 +17,9 @@ public static class Runner /// [0] = CreateDatabase, DropDatabase /// [1] = Name of Database /// - public static void Main(string [] args) + public static void Main(string[] args) { - if (args == null || args.Length < 1) + if (!args.Any() || args.Length < 1) { throw new ArgumentException("Utility name not provided."); } diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs index e5e460ec7e..a09c9313a8 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Microsoft.Data.SqlClient.TestUtilities; using Microsoft.SqlServer.Management.Common; @@ -35,7 +36,7 @@ public static class SqlDbManager /// public static void Run(string[] args) { - if (args == null || args.Length < 2) + if (!args.Any() || args.Length < 2) { throw new InvalidArgumentException("Incomplete arguments provided."); } @@ -162,9 +163,9 @@ private static void DropIfExistsDatabase(string dbName, ServerConnection context string dropScript = $"IF EXISTS (select * from sys.databases where name = '{dbName}') BEGIN DROP DATABASE [{dbName}] END;"; context.ExecuteNonQuery(dropScript); } - catch + catch (ExecutionFailureException ex) { - Console.WriteLine($"FAILED to drop database '{dbName}'"); + Console.WriteLine($"FAILED to drop database '{dbName}'. Error message: {ex.Message}"); } } @@ -176,7 +177,15 @@ private static void CreateDatabase(string dbName, ServerConnection context) try { createScript = createScript.Replace(DB_Northwind, dbName); - context.ExecuteNonQuery(createScript); + try + { + context.ExecuteNonQuery(createScript); + } + catch (ExecutionFailureException ex) + { + Console.WriteLine(ex.Message); + throw; + } } catch (Exception) {