Fix OE with dbpool connection (#1197)

* Fix OE with dbpool connection

* Remove extra whitespace

* Remove hard-coded number
This commit is contained in:
Karl Burtram
2021-05-05 14:24:45 -07:00
committed by GitHub
parent e123c24210
commit 63aa6758e8
3 changed files with 37 additions and 9 deletions

View File

@@ -8,6 +8,7 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Threading; using System.Threading;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.Utility; using Microsoft.SqlTools.Utility;
@@ -25,7 +26,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
// the user connected directly to the master of a readable secondary // the user connected directly to the master of a readable secondary
// In that case, the name in the connection string won't be found in sys.databases // In that case, the name in the connection string won't be found in sys.databases
// We detect that here and fall back to master // We detect that here and fall back to master
if (db.State == SqlSmoState.Creating) if (db.State == SqlSmoState.Creating && !IsDWGen3(db))
{ {
db = new Database(serverNode.GetContextAs<SmoQueryContext>().Server, "master"); db = new Database(serverNode.GetContextAs<SmoQueryContext>().Server, "master");
db.Refresh(); db.Refresh();
@@ -75,12 +76,28 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
} }
catch (Exception ex) catch (Exception ex)
{ {
var error = string.Format(CultureInfo.InvariantCulture, "Failed to get IsAccessible. error:{0} inner:{1} stacktrace:{2}", // IsAccessible is not set of DW Gen3 so exception is expected in this case
ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace); if (IsDWGen3(context?.Database))
Logger.Write(TraceEventType.Error, error); {
ErrorMessage = ex.Message; return true;
return false; }
else
{
var error = string.Format(CultureInfo.InvariantCulture, "Failed to get IsAccessible. error:{0} inner:{1} stacktrace:{2}",
ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace);
Logger.Write(TraceEventType.Error, error);
ErrorMessage = ex.Message;
return false;
}
} }
} }
private bool IsDWGen3(Database db)
{
return db != null
&& db.DatabaseEngineEdition == DatabaseEngineEdition.SqlDataWarehouse
&& db.ServerVersion.Major == 12;
}
} }
} }

View File

@@ -4,6 +4,7 @@
// //
using System; using System;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts; using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
@@ -22,7 +23,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
Sql2016, Sql2016,
Sql2017, Sql2017,
AzureV12, AzureV12,
SqlOnDemand SqlOnDemand,
AzureSqlDWGen3
} }
/// <summary> /// <summary>
@@ -59,7 +61,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
ValidForFlag validforFlag = ValidForFlag.All; ValidForFlag validforFlag = ValidForFlag.All;
if (Enum.TryParse<ValidForFlag>(serverType.ToString(), out validforFlag)) if (Enum.TryParse<ValidForFlag>(serverType.ToString(), out validforFlag))
{ {
if (isSqlDw && serverType == SqlServerType.AzureV12) if ((isSqlDw && serverType == SqlServerType.AzureV12) || serverType == SqlServerType.AzureSqlDWGen3)
{ {
validforFlag = ValidForFlag.SqlDw; validforFlag = ValidForFlag.SqlDw;
} }
@@ -90,7 +92,15 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
} }
else if (serverInfo.IsCloud) else if (serverInfo.IsCloud)
{ {
serverType = SqlServerType.AzureV12; if (serverInfo.EngineEditionId == (int)DatabaseEngineEdition.SqlDataWarehouse
&& serverVersion.StartsWith("12", StringComparison.Ordinal))
{
serverType = SqlServerType.AzureSqlDWGen3;
}
else
{
serverType = SqlServerType.AzureV12;
}
} }
else if (!string.IsNullOrWhiteSpace(serverVersion)) else if (!string.IsNullOrWhiteSpace(serverVersion))
{ {

View File

@@ -21,6 +21,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
Sql2017 = 0x40, Sql2017 = 0x40,
SqlDw = 0x80, SqlDw = 0x80,
SqlOnDemand = 0x100, SqlOnDemand = 0x100,
AzureSqlDWGen3 = 0x200,
AllOnPrem = Sql2005 | Sql2008 | Sql2012 | Sql2014 | Sql2016 | Sql2017, AllOnPrem = Sql2005 | Sql2008 | Sql2012 | Sql2014 | Sql2016 | Sql2017,
AllAzure = AzureV12, AllAzure = AzureV12,
All = Sql2005 | Sql2008 | Sql2012 | Sql2014 | Sql2016 | Sql2017 | AzureV12 | SqlDw | SqlOnDemand, All = Sql2005 | Sql2008 | Sql2012 | Sql2014 | Sql2016 | Sql2017 | AzureV12 | SqlDw | SqlOnDemand,