mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Fix OE with dbpool connection (#1197)
* Fix OE with dbpool connection * Remove extra whitespace * Remove hard-coded number
This commit is contained in:
@@ -8,6 +8,7 @@ using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
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
|
||||
// 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
|
||||
if (db.State == SqlSmoState.Creating)
|
||||
if (db.State == SqlSmoState.Creating && !IsDWGen3(db))
|
||||
{
|
||||
db = new Database(serverNode.GetContextAs<SmoQueryContext>().Server, "master");
|
||||
db.Refresh();
|
||||
@@ -75,12 +76,28 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
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;
|
||||
// IsAccessible is not set of DW Gen3 so exception is expected in this case
|
||||
if (IsDWGen3(context?.Database))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
|
||||
@@ -22,7 +23,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
Sql2016,
|
||||
Sql2017,
|
||||
AzureV12,
|
||||
SqlOnDemand
|
||||
SqlOnDemand,
|
||||
AzureSqlDWGen3
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -59,7 +61,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
ValidForFlag validforFlag = ValidForFlag.All;
|
||||
if (Enum.TryParse<ValidForFlag>(serverType.ToString(), out validforFlag))
|
||||
{
|
||||
if (isSqlDw && serverType == SqlServerType.AzureV12)
|
||||
if ((isSqlDw && serverType == SqlServerType.AzureV12) || serverType == SqlServerType.AzureSqlDWGen3)
|
||||
{
|
||||
validforFlag = ValidForFlag.SqlDw;
|
||||
}
|
||||
@@ -90,7 +92,15 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
}
|
||||
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))
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
Sql2017 = 0x40,
|
||||
SqlDw = 0x80,
|
||||
SqlOnDemand = 0x100,
|
||||
AzureSqlDWGen3 = 0x200,
|
||||
AllOnPrem = Sql2005 | Sql2008 | Sql2012 | Sql2014 | Sql2016 | Sql2017,
|
||||
AllAzure = AzureV12,
|
||||
All = Sql2005 | Sql2008 | Sql2012 | Sql2014 | Sql2016 | Sql2017 | AzureV12 | SqlDw | SqlOnDemand,
|
||||
|
||||
Reference in New Issue
Block a user