From d222af7824658aea9b33fcb5206b6cee60b6a273 Mon Sep 17 00:00:00 2001 From: Kevin Cunnane Date: Thu, 19 Oct 2017 22:08:33 -0700 Subject: [PATCH] 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. --- .../AdminServicesProviderOptionsHelper.cs | 2 + .../Admin/Database/DatabasePrototype.cs | 13 ++- .../Admin/Database/DatabasePrototypeAzure.cs | 22 ++--- .../Admin/Database/DatabaseTaskHelper.cs | 11 +++ .../Connection/ConnectionInfo.cs | 19 ++-- .../Connection/ConnectionService.cs | 5 +- .../ReliableConnection/CachedServerInfo.cs | 8 +- .../ReliableConnectionHelper.cs | 89 +++++++++---------- .../DisasterRecoveryService.cs | 4 +- .../Localization/sr.cs | 22 +++++ .../Localization/sr.resx | 8 ++ .../Localization/sr.strings | 2 + .../Localization/sr.xlf | 10 +++ .../Scripting/Scripter.cs | 1 + .../Scripting/ScripterCore.cs | 7 +- .../Connection/ReliableConnectionTests.cs | 1 - 16 files changed, 145 insertions(+), 79 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminServicesProviderOptionsHelper.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminServicesProviderOptionsHelper.cs index ba2d5d99..3533f36b 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminServicesProviderOptionsHelper.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminServicesProviderOptionsHelper.cs @@ -46,6 +46,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin internal const string FileGroup = "fileGroup"; internal const string InitialSize = "initialSize"; internal const string IsPrimaryFile = "isPrimaryFile"; + internal const string AzureEdition = "azureEdition"; + internal const string ServiceLevelObjective = "serviceLevelObjective"; internal static AdminServicesProviderOptions BuildAdminServicesProviderOptions() diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs index 39b582a3..13ad867c 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs @@ -47,6 +47,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin public ContainmentType databaseContainmentType; public PageVerify pageVerify; public AzureEdition azureEdition; + public string azureEditionDisplayValue; public string configuredServiceLevelObjective; public string currentServiceLevelObjective; public DbSize maxSize; @@ -151,6 +152,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin this.filestreamDirectoryName = String.Empty; this.delayedDurability = DelayedDurability.Disabled; this.azureEdition = AzureEdition.Standard; + this.azureEditionDisplayValue = AzureEdition.Standard.ToString(); this.configuredServiceLevelObjective = String.Empty; this.currentServiceLevelObjective = String.Empty; this.maxSize = new DbSize(0, DbSize.SizeUnits.MB); @@ -264,6 +266,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin if (context.Server.ServerType == DatabaseEngineType.SqlAzureDatabase) { //These properties are only available for Azure DBs this.azureEdition = AzureEdition.Standard; + this.azureEditionDisplayValue = azureEdition.ToString(); this.currentServiceLevelObjective = AzureSqlDbHelper.GetDefaultServiceObjective(this.azureEdition); this.configuredServiceLevelObjective = AzureSqlDbHelper.GetDefaultServiceObjective(this.azureEdition); this.maxSize = AzureSqlDbHelper.GetDatabaseDefaultSize(this.azureEdition); @@ -585,6 +588,7 @@ WHERE do.database_id = @DbID //Only fill in the Azure properties when connected to an Azure server if (context.Server.ServerType == DatabaseEngineType.SqlAzureDatabase) { + this.azureEditionDisplayValue = db.AzureEdition; AzureEdition edition; if (Enum.TryParse(db.AzureEdition, true, out edition)) { @@ -592,8 +596,8 @@ WHERE do.database_id = @DbID } else { - //Unknown Azure DB Edition so we can't continue - throw new Exception("CreateDatabaseOptionsSR.Error_UnknownAzureEdition(db.AzureEdition)"); + // Unknown Azure DB Edition so we can't set a value, leave as default Standard + // Note that this is likely a } //Size is in MB, but if it's greater than a GB we want to display the size in GB @@ -725,6 +729,7 @@ WHERE do.database_id = @DbID this.targetRecoveryTime = other.targetRecoveryTime; this.delayedDurability = other.delayedDurability; this.azureEdition = other.azureEdition; + this.azureEditionDisplayValue = other.azureEditionDisplayValue; this.configuredServiceLevelObjective = other.configuredServiceLevelObjective; this.currentServiceLevelObjective = other.currentServiceLevelObjective; this.legacyCardinalityEstimation = other.legacyCardinalityEstimation; @@ -1915,7 +1920,7 @@ WHERE do.database_id = @DbID if (!FileNameHelper.IsValidFilename(this.FilestreamDirectoryName)) { string message = String.Format(System.Globalization.CultureInfo.InvariantCulture, - "CreateDatabaseOptionsSR.Error_InvalidDirectoryName {0}", + SR.Error_InvalidDirectoryName, this.FilestreamDirectoryName); throw new ArgumentException(message); } @@ -1940,7 +1945,7 @@ WHERE do.database_id = @DbID if (rowCount != 0) { string message = String.Format(System.Globalization.CultureInfo.InvariantCulture, - "CreateDatabaseOptionsSR.Error_ExistingDirectoryName {0} {1}", + SR.Error_ExistingDirectoryName, this.FilestreamDirectoryName, this.Name); throw new ArgumentException(message); diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototypeAzure.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototypeAzure.cs index f7b2a83e..8f1ddd76 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototypeAzure.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototypeAzure.cs @@ -3,18 +3,15 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using System.ComponentModel; -using System.Text; -using Microsoft.SqlServer.Management.Smo; -using Microsoft.SqlServer.Management.Sdk.Sfc; -using Microsoft.SqlServer.Management.Diagnostics; -using System.Globalization; -using System.Data.SqlClient; -using AzureEdition = Microsoft.SqlTools.ServiceLayer.Admin.AzureSqlDbHelper.AzureEdition; -using Microsoft.SqlServer.Management.Common; -using System; using System.Collections.Generic; +using System.ComponentModel; +using System.Data.SqlClient; +using System.Globalization; using System.Linq; +using Microsoft.SqlServer.Management.Common; +using Microsoft.SqlServer.Management.Sdk.Sfc; +using Microsoft.SqlServer.Management.Smo; +using AzureEdition = Microsoft.SqlTools.ServiceLayer.Admin.AzureSqlDbHelper.AzureEdition; namespace Microsoft.SqlTools.ServiceLayer.Admin { @@ -102,10 +99,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin { get { - return AzureSqlDbHelper.GetAzureEditionDisplayName(this.currentState.azureEdition); + return this.currentState.azureEditionDisplayValue; } set { + // TODO set from here should probably allow for the fact that System is a valid edition for + // actual system DBs. Not handling for now AzureEdition edition; if (AzureSqlDbHelper.TryGetAzureEditionFromDisplayName(value, out edition)) { @@ -115,6 +114,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin } this.currentState.azureEdition = edition; + this.currentState.azureEditionDisplayValue = value; this.CurrentServiceLevelObjective = AzureSqlDbHelper.GetDefaultServiceObjective(edition); this.MaxSize = AzureSqlDbHelper.GetDatabaseDefaultSize(edition).ToString(); this.NotifyObservers(); diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs index 7179db54..9730b0f0 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs @@ -150,9 +150,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.IsPrimaryFile, file.IsPrimaryFile); } + AddAzureProperties(databaseInfo, prototype as DatabasePrototypeAzure); + return databaseInfo; } + private static void AddAzureProperties(DatabaseInfo databaseInfo, DatabasePrototypeAzure prototype) + { + if (prototype == null) { return; } + + databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.AzureEdition, prototype.AzureEditionDisplay); + databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.ServiceLevelObjective, prototype.CurrentServiceLevelObjective); + + } + private static string GetBackupDate(DateTime backupDate) { if (backupDate == null diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs index 457fa985..49a561f1 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs @@ -63,10 +63,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection public InteractionMetrics IntellisenseMetrics { get; private set; } /// - /// Returns true is the db connection is to a SQL db + /// Returns true if the db connection is to any cloud instance /// - public bool IsAzure { get; set; } - + public bool IsCloud { get; set; } + + /// + /// Returns true if the db connection is to a SQL db instance + /// + public bool IsSqlDb { get; set; } + /// Returns true if the sql connection is to a DW instance /// 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); } /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs index 2d7acbde..3ac98185 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs @@ -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 { - { TelemetryPropertyNames.IsAzure, connectionInfo.IsAzure.ToOneOrZeroString() } + { TelemetryPropertyNames.IsAzure, connectionInfo.IsCloud.ToOneOrZeroString() } }, EventName = TelemetryEventNames.IntellisenseQuantile, Measures = connectionInfo.IntellisenseMetrics.Quantile diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/CachedServerInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/CachedServerInfo.cs index 71f3f505..7ab2bd2b 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/CachedServerInfo.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/CachedServerInfo.cs @@ -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); diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/ReliableConnectionHelper.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/ReliableConnectionHelper.cs index fe6db5f8..b7d4620d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/ReliableConnectionHelper.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/ReliableConnectionHelper.cs @@ -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> cloudEditions = new Lazy>(() => new HashSet() + { + (int)DatabaseEngineEdition.SqlDatabase, + (int)DatabaseEngineEdition.SqlDataWarehouse, + (int)DatabaseEngineEdition.SqlStretchDatabase, + // Note: for now, ignoring managed instance as it should be treated just like on prem. + }); + /// /// Opens the connection and sets the lock/command timeout and pooling=false. /// @@ -457,7 +465,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection private static bool IsCloudEngineId(int engineEditionId) { - return engineEditionId == SqlAzureEngineEditionId; + return cloudEditions.Value.Contains(engineEditionId); } /// @@ -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 diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs index d32bae38..8557c738 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs @@ -146,7 +146,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery { using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(connInfo, "Backup")) { - if (sqlConn != null && !connInfo.IsSqlDW && !connInfo.IsAzure) + if (sqlConn != null && !connInfo.IsCloud) { BackupConfigInfo backupConfigInfo = this.GetBackupConfigInfo(helper.DataContainer, sqlConn, sqlConn.Database); backupConfigInfo.DatabaseInfo = AdminService.GetDatabaseInfo(connInfo); @@ -346,7 +346,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery { using (sqlConn = ConnectionService.OpenSqlConnection(connInfo, "DisasterRecovery")) { - if (sqlConn != null && !connInfo.IsSqlDW && !connInfo.IsAzure) + if (sqlConn != null && !connInfo.IsCloud) { connectionInfo = connInfo; return true; diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs index a3fdb6bf..0fb58c60 100755 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs @@ -3309,6 +3309,22 @@ namespace Microsoft.SqlTools.ServiceLayer } } + public static string Error_InvalidDirectoryName + { + get + { + return Keys.GetString(Keys.Error_InvalidDirectoryName); + } + } + + public static string Error_ExistingDirectoryName + { + get + { + return Keys.GetString(Keys.Error_ExistingDirectoryName); + } + } + public static string BackupTaskName { get @@ -4915,6 +4931,12 @@ namespace Microsoft.SqlTools.ServiceLayer public const string NeverBackedUp = "NeverBackedUp"; + public const string Error_InvalidDirectoryName = "Error_InvalidDirectoryName"; + + + public const string Error_ExistingDirectoryName = "Error_ExistingDirectoryName"; + + public const string BackupTaskName = "BackupTaskName"; diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx index 88515160..8c948393 100755 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx @@ -1827,6 +1827,14 @@ Never + + Path {0} is not a valid directory + + + + For directory {0} a file with name {1} already exists + + Backup Database diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings index fe050287..cd65c296 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings @@ -808,6 +808,8 @@ general_containmentType_Partial = Partial filegroups_filestreamFiles = FILESTREAM Files prototype_file_noApplicableFileGroup = No Applicable Filegroup NeverBackedUp = Never +Error_InvalidDirectoryName = Path {0} is not a valid directory +Error_ExistingDirectoryName = For directory {0} a file with name {1} already exists ############################################################################ # Backup Service diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf index 5d8d3424..79bb6be2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf @@ -2295,6 +2295,16 @@ Azure SQL Stretch Database + + Path {0} is not a valid directory + Path {0} is not a valid directory + + + + For directory {0} a file with name {1} already exists + For directory {0} a file with name {1} already exists + + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Scripting/Scripter.cs b/src/Microsoft.SqlTools.ServiceLayer/Scripting/Scripter.cs index a20e1d5c..388463a1 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Scripting/Scripter.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Scripting/Scripter.cs @@ -40,6 +40,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting targetDatabaseEngineEditionMap.Add(DatabaseEngineEdition.SqlDatabase, "SqlAzureDatabaseEdition"); targetDatabaseEngineEditionMap.Add(DatabaseEngineEdition.SqlDataWarehouse, "SqlDatawarehouseEdition"); targetDatabaseEngineEditionMap.Add(DatabaseEngineEdition.SqlStretchDatabase, "SqlServerStretchEdition"); + targetDatabaseEngineEditionMap.Add(DatabaseEngineEdition.SqlManagedInstance, "SqlServerManagedInstance"); // Mapping for database engine type serverVersionMap.Add(9, "Script90Compat"); diff --git a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScripterCore.cs b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScripterCore.cs index 234757e7..fa6903d3 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScripterCore.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScripterCore.cs @@ -96,7 +96,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting { Logger.Write(LogLevel.Error, "Exception at PeekDefinition Database.get() : " + cfe.Message); this.error = true; - this.errorMessage = (connectionInfo != null && connectionInfo.IsAzure) ? SR.PeekDefinitionAzureError(cfe.Message) : SR.PeekDefinitionError(cfe.Message); + this.errorMessage = (connectionInfo != null && connectionInfo.IsCloud) ? SR.PeekDefinitionAzureError(cfe.Message) : SR.PeekDefinitionError(cfe.Message); return null; } catch (Exception ex) @@ -513,7 +513,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting internal string GetTargetDatabaseEngineEdition() { DatabaseEngineEdition dbEngineEdition = this.serverConnection.DatabaseEngineEdition; - string dbEngineEditionString = targetDatabaseEngineEditionMap[dbEngineEdition]; + string dbEngineEditionString; + targetDatabaseEngineEditionMap.TryGetValue(dbEngineEdition, out dbEngineEditionString); return (dbEngineEditionString != null) ? dbEngineEditionString : "SqlServerEnterpriseEdition"; } @@ -526,7 +527,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting internal string GetTargetDatabaseEngineType() { - return connectionInfo.IsAzure ? "SqlAzure" : "SingleInstance"; + return connectionInfo.IsCloud ? "SqlAzure" : "SingleInstance"; } internal bool LineContainsObject(string line, string objectName, string createSyntax) diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Connection/ReliableConnectionTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Connection/ReliableConnectionTests.cs index b531ca5e..27d4b30d 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Connection/ReliableConnectionTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Connection/ReliableConnectionTests.cs @@ -317,7 +317,6 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection Assert.True(serverInfo.ServerEdition == serverInfo2.ServerEdition); Assert.True(serverInfo.IsCloud == serverInfo2.IsCloud); Assert.True(serverInfo.AzureVersion == serverInfo2.AzureVersion); - Assert.True(serverInfo.IsAzureV1 == serverInfo2.IsAzureV1); } }