Skip to content

Commit

Permalink
Improving code on test lab on ExtUtilities (#1004)
Browse files Browse the repository at this point in the history
  • Loading branch information
Javad authored Mar 31, 2021
1 parent 961e46f commit b079be9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -16,9 +17,9 @@ public static class Runner
/// [0] = CreateDatabase, DropDatabase
/// [1] = Name of Database
/// </param>
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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -35,7 +36,7 @@ public static class SqlDbManager
/// </param>
public static void Run(string[] args)
{
if (args == null || args.Length < 2)
if (!args.Any() || args.Length < 2)
{
throw new InvalidArgumentException("Incomplete arguments provided.");
}
Expand Down Expand Up @@ -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}");
}
}

Expand All @@ -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)
{
Expand Down

0 comments on commit b079be9

Please sign in to comment.