Handles a null reference exception (#2079)

This commit is contained in:
Cheena Malhotra
2023-05-31 16:38:52 -07:00
committed by GitHub
parent d5cfc52ca7
commit 478b10d391

View File

@@ -42,10 +42,14 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
/// </summary> /// </summary>
public static ValidForFlag GetValidForFlag(SqlServerType serverType, Database database = null) public static ValidForFlag GetValidForFlag(SqlServerType serverType, Database database = null)
{ {
var isSqlDw = false; bool isSqlDw = false;
try try
{ {
isSqlDw = database.IsSqlDw; // Database could be null here, handle NRE first.
if (database != null)
{
isSqlDw = database.IsSqlDw;
}
} }
catch (Exception e) catch (Exception e)
{ {
@@ -54,7 +58,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
Logger.Information($"This exception is expected when we are trying to access a readonly database. Exception: {e.Message}"); Logger.Information($"This exception is expected when we are trying to access a readonly database. Exception: {e.Message}");
} }
return GetValidForFlag(serverType, database != null && isSqlDw); return GetValidForFlag(serverType, isSqlDw);
} }
/// <summary> /// <summary>