Skip to content

Commit b0d0b2a

Browse files
authored
Improve error reporting from SqlDbManager (#1617)
1 parent 2c56830 commit b0d0b2a

File tree

1 file changed

+6
-3
lines changed
  • src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities

1 file changed

+6
-3
lines changed

src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.ExtUtilities/SqlDbManager.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public static void Run(string[] args)
5555
builder.InitialCatalog = DB_Master;
5656
using (SqlConnection conn = new SqlConnection(builder.ConnectionString))
5757
{
58+
Console.WriteLine($"Connecting to {builder.DataSource}");
5859
SqlServer.Management.Smo.Server server = new SqlServer.Management.Smo.Server(new ServerConnection(conn));
5960
ServerConnection context = server.ConnectionContext;
6061

@@ -102,7 +103,7 @@ public static void Run(string[] args)
102103
}
103104
catch (Exception e)
104105
{
105-
throw new Exception($"{args[0]} execution failed with Error: {e.Message}");
106+
throw new Exception($"{args[0]} execution failed with Error: {e}");
106107
}
107108
}
108109

@@ -158,14 +159,15 @@ private static void UpdateConfig(string key, SqlConnectionStringBuilder builder)
158159

159160
private static void DropIfExistsDatabase(string dbName, ServerConnection context)
160161
{
162+
Console.WriteLine($"Dropping database [{dbName}] if it exists");
161163
try
162164
{
163165
string dropScript = $"IF EXISTS (select * from sys.databases where name = '{dbName}') BEGIN DROP DATABASE [{dbName}] END;";
164166
context.ExecuteNonQuery(dropScript);
165167
}
166168
catch (ExecutionFailureException ex)
167169
{
168-
Console.WriteLine($"FAILED to drop database '{dbName}'. Error message: {ex.Message}");
170+
Console.WriteLine($"FAILED to drop database '{dbName}'. Error message: {ex}");
169171
}
170172
}
171173

@@ -174,6 +176,7 @@ private static void CreateDatabase(string dbName, ServerConnection context)
174176
DropIfExistsDatabase(dbName, context);
175177
string createScript = File.ReadAllText(NorthWindScriptPath);
176178

179+
Console.WriteLine($"Creating database [{dbName}]");
177180
try
178181
{
179182
createScript = createScript.Replace(DB_Northwind, dbName);
@@ -183,7 +186,7 @@ private static void CreateDatabase(string dbName, ServerConnection context)
183186
}
184187
catch (ExecutionFailureException ex)
185188
{
186-
Console.WriteLine(ex.Message);
189+
Console.WriteLine(ex);
187190
throw;
188191
}
189192
}

0 commit comments

Comments
 (0)