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,11 +42,15 @@ 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
{
// Database could be null here, handle NRE first.
if (database != null)
{ {
isSqlDw = database.IsSqlDw; isSqlDw = database.IsSqlDw;
} }
}
catch (Exception e) catch (Exception e)
{ {
// Incase of dataverses, isSqlDw creates a temp table to check if the database is accessible, however dataverse // Incase of dataverses, isSqlDw creates a temp table to check if the database is accessible, however dataverse
@@ -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>