Fix numerous Azure property issues (#511)

* Avoid crashing if azure edition is System.

* Add new Azure-specific options to the prototype and return through the service calls

* Send azure properties over database info request

* IsCloud should include Azure SQL DW
- Fixed references to this feature flag
- Updated edition handling to include ManagedInstance and removed AzureV1 check since it's never used and it's been retired.
This commit is contained in:
Kevin Cunnane
2017-10-19 22:08:33 -07:00
committed by Karl Burtram
parent 49f0221dc8
commit d222af7824
16 changed files with 145 additions and 79 deletions

View File

@@ -63,10 +63,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
public InteractionMetrics<double> IntellisenseMetrics { get; private set; }
/// <summary>
/// Returns true is the db connection is to a SQL db
/// Returns true if the db connection is to any cloud instance
/// </summary>
public bool IsAzure { get; set; }
public bool IsCloud { get; set; }
/// <summary>
/// Returns true if the db connection is to a SQL db instance
/// </summary>
public bool IsSqlDb { get; set; }
/// Returns true if the sql connection is to a DW instance
/// </summary>
public bool IsSqlDW { get; set; }
@@ -99,10 +104,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
}
}
public bool HasConnectionType(string connectionType)
{
connectionType = connectionType ?? ConnectionType.Default;
return ConnectionTypeToConnectionMap.ContainsKey(connectionType);
public bool HasConnectionType(string connectionType)
{
connectionType = connectionType ?? ConnectionType.Default;
return ConnectionTypeToConnectionMap.ContainsKey(connectionType);
}
/// <summary>

View File

@@ -463,8 +463,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
OsVersion = serverInfo.OsVersion,
MachineName = serverInfo.MachineName
};
connectionInfo.IsAzure = serverInfo.IsCloud;
connectionInfo.IsCloud = serverInfo.IsCloud;
connectionInfo.MajorVersion = serverInfo.ServerMajorVersion;
connectionInfo.IsSqlDb = serverInfo.EngineEditionId == (int)DatabaseEngineEdition.SqlDatabase;
connectionInfo.IsSqlDW = (serverInfo.EngineEditionId == (int)DatabaseEngineEdition.SqlDataWarehouse);
}
catch (Exception ex)
@@ -1293,7 +1294,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
{
Properties = new Dictionary<string, string>
{
{ TelemetryPropertyNames.IsAzure, connectionInfo.IsAzure.ToOneOrZeroString() }
{ TelemetryPropertyNames.IsAzure, connectionInfo.IsCloud.ToOneOrZeroString() }
},
EventName = TelemetryEventNames.IntellisenseQuantile,
Measures = connectionInfo.IntellisenseMetrics.Quantile

View File

@@ -37,7 +37,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
public enum CacheVariable {
IsSqlDw,
IsAzure
IsAzure,
IsCloud
}
#region CacheKey implementation
@@ -151,6 +152,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
}
}
public void AddOrUpdateIsCloud(IDbConnection connection, bool isCloud)
{
AddOrUpdateCache(connection, isCloud, CacheVariable.IsCloud);
}
public void AddOrUpdateIsAzure(IDbConnection connection, bool isAzure)
{
AddOrUpdateCache(connection, isAzure, CacheVariable.IsAzure);

View File

@@ -34,6 +34,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
// http://msdn.microsoft.com/en-us/library/ee336261.aspx
private const int SqlAzureEngineEditionId = 5;
private static Lazy<HashSet<int>> cloudEditions = new Lazy<HashSet<int>>(() => new HashSet<int>()
{
(int)DatabaseEngineEdition.SqlDatabase,
(int)DatabaseEngineEdition.SqlDataWarehouse,
(int)DatabaseEngineEdition.SqlStretchDatabase,
// Note: for now, ignoring managed instance as it should be treated just like on prem.
});
/// <summary>
/// Opens the connection and sets the lock/command timeout and pooling=false.
/// </summary>
@@ -457,7 +465,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
private static bool IsCloudEngineId(int engineEditionId)
{
return engineEditionId == SqlAzureEngineEditionId;
return cloudEditions.Value.Contains(engineEditionId);
}
/// <summary>
@@ -685,14 +693,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
// of this, we must detect the presence of the column to determine if we can query for Selective Xml Indexes
public bool IsSelectiveXmlIndexMetadataPresent;
public bool IsAzureV1
{
get
{
return IsCloud && AzureVersion == 1;
}
}
public string OsVersion;
public string MachineName;
@@ -782,7 +782,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
try
{
CachedServerInfo.Instance.AddOrUpdateIsAzure(connection, serverInfo.IsCloud);
CachedServerInfo.Instance.AddOrUpdateIsCloud(connection, serverInfo.IsCloud);
}
catch (Exception ex)
{
@@ -949,49 +949,42 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
}
// SQL Azure does not support custom DBCompat values.
if (!serverInfo.IsAzureV1)
SqlParameter databaseNameParameter = new SqlParameter(
"@dbname",
SqlDbType.NChar,
128,
ParameterDirection.Input,
false,
0,
0,
null,
DataRowVersion.Default,
tempDatabaseName);
object compatibilityLevel;
using (IDbCommand versionCommand = connection.CreateCommand())
{
SqlParameter databaseNameParameter = new SqlParameter(
"@dbname",
SqlDbType.NChar,
128,
ParameterDirection.Input,
false,
0,
0,
null,
DataRowVersion.Default,
tempDatabaseName);
versionCommand.CommandText = "SELECT compatibility_level FROM sys.databases WITH (NOLOCK) WHERE name = @dbname";
versionCommand.CommandType = CommandType.Text;
versionCommand.Parameters.Add(databaseNameParameter);
compatibilityLevel = versionCommand.ExecuteScalar();
}
object compatibilityLevel;
using (IDbCommand versionCommand = connection.CreateCommand())
{
versionCommand.CommandText = "SELECT compatibility_level FROM sys.databases WITH (NOLOCK) WHERE name = @dbname";
versionCommand.CommandType = CommandType.Text;
versionCommand.Parameters.Add(databaseNameParameter);
compatibilityLevel = versionCommand.ExecuteScalar();
}
// value is null if db is not online
foundVersion = compatibilityLevel != null && !(compatibilityLevel is DBNull);
if(foundVersion)
{
tempDbCompatibilityLevel = (byte)compatibilityLevel;
}
else
{
string conString = connection.ConnectionString == null ? "null" : connection.ConnectionString;
string dbName = tempDatabaseName == null ? "null" : tempDatabaseName;
string message = string.Format(CultureInfo.CurrentCulture,
"Querying database compatibility level failed. Connection string: '{0}'. dbname: '{1}'.",
conString, dbName);
Tracer.TraceEvent(TraceEventType.Error, TraceId.CoreServices, message);
}
// value is null if db is not online
foundVersion = compatibilityLevel != null && !(compatibilityLevel is DBNull);
if(foundVersion)
{
tempDbCompatibilityLevel = (byte)compatibilityLevel;
}
else
{
foundVersion = true;
string conString = connection.ConnectionString == null ? "null" : connection.ConnectionString;
string dbName = tempDatabaseName == null ? "null" : tempDatabaseName;
string message = string.Format(CultureInfo.CurrentCulture,
"Querying database compatibility level failed. Connection string: '{0}'. dbname: '{1}'.",
conString, dbName);
Tracer.TraceEvent(TraceEventType.Error, TraceId.CoreServices, message);
}
},
catchException: null, // Always throw