diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs index e634ac0d..85ea46f7 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs @@ -151,7 +151,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin } await requestContext.SendResult(new GetDatabaseInfoResponse(){ - Result = info + DatabaseInfo = info }); } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminServicesProviderOptionsHelper.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminServicesProviderOptionsHelper.cs index b1a973cd..ba2d5d99 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminServicesProviderOptionsHelper.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminServicesProviderOptionsHelper.cs @@ -32,6 +32,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin internal const string DatabaseContainmentType = "databaseContainmentType"; internal const string DatabaseState = "databaseState"; internal const string RecoveryModel = "recoveryModel"; + internal const string CompatibilityLevel = "compatibilityLevel"; + internal const string LastBackupDate = "lastBackupDate"; + internal const string LastLogBackupDate = "lastLogBackupDate"; internal const string FileGroupType = "fileGroupType"; internal const string IsDefault = "isDefault"; internal const string IsFileStream = "isFileStream"; @@ -205,6 +208,33 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin GroupName = "Other" }, new ServiceOption + { + Name = AdminServicesProviderOptionsHelper.LastBackupDate, + DisplayName = "LastBackupDate", + Description = "Last backup date", + ValueType = ServiceOption.ValueTypeString, + IsRequired = false, + GroupName = "Other" + }, + new ServiceOption + { + Name = AdminServicesProviderOptionsHelper.LastLogBackupDate, + DisplayName = "LastLogBackupDate", + Description = "Last log backup date", + ValueType = ServiceOption.ValueTypeString, + IsRequired = false, + GroupName = "Other" + }, + new ServiceOption + { + Name = AdminServicesProviderOptionsHelper.CompatibilityLevel, + DisplayName = "CompatibilityLevel", + Description = "Compatibility level", + ValueType = ServiceOption.ValueTypeString, + IsRequired = false, + GroupName = "Other" + }, + new ServiceOption { Name = AdminServicesProviderOptionsHelper.FileGroups, DisplayName = "File Groups", diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Contracts/GetDatabaseInfoRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Contracts/GetDatabaseInfoRequest.cs index da3c6d61..35a6b3bc 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Contracts/GetDatabaseInfoRequest.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Contracts/GetDatabaseInfoRequest.cs @@ -26,7 +26,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin.Contracts /// /// The object containing the database info /// - public DatabaseInfo Result { get; set; } + public DatabaseInfo DatabaseInfo { get; set; } } /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs index 49225727..c726f9f3 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs @@ -38,6 +38,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin public string collation; public RecoveryModel recoveryModel; + public DateTime lastBackupDate; + public DateTime lastLogBackupDate; public DatabaseUserAccess restrictAccess; public DatabaseStatus databaseState; public DefaultCursor defaultCursor; @@ -373,6 +375,16 @@ WHERE do.database_id = @DbID this.recoveryModel = db.DatabaseOptions.RecoveryModel; } + if (db.IsSupportedProperty("LastBackupDate")) + { + this.lastBackupDate = db.LastBackupDate; + } + + if (db.IsSupportedProperty("LastLogBackupDate")) + { + this.lastLogBackupDate = db.LastLogBackupDate; + } + if (Utils.IsSql12OrLater(context.Server.Information.Version.Major)) { this.autoCreateStatisticsIncremental = db.DatabaseOptions.AutoCreateStatisticsIncremental; @@ -651,6 +663,8 @@ WHERE do.database_id = @DbID this.name = other.name; this.collation = other.collation; this.recoveryModel = other.recoveryModel; + this.lastBackupDate = other.lastBackupDate; + this.lastLogBackupDate = other.lastLogBackupDate; this.restrictAccess = other.restrictAccess; this.databaseState = other.databaseState; this.defaultCursor = other.defaultCursor; @@ -730,6 +744,8 @@ WHERE do.database_id = @DbID { bool result = (this.recoveryModel == other.recoveryModel) && + (this.lastBackupDate == other.lastBackupDate) && + (this.lastLogBackupDate == other.lastLogBackupDate) && (this.restrictAccess == other.restrictAccess) && (this.databaseState == other.databaseState) && (this.defaultCursor == other.defaultCursor) && @@ -891,6 +907,40 @@ WHERE do.database_id = @DbID } } + /// + /// The last backup date for the database + /// + [Browsable(false)] + public DateTime LastBackupDate + { + get + { + return this.currentState.lastBackupDate; + } + set + { + this.currentState.lastBackupDate = value; + this.NotifyObservers(); + } + } + + /// + /// The last log backup date for the database + /// + [Browsable(false)] + public DateTime LastLogBackupDate + { + get + { + return this.currentState.lastLogBackupDate; + } + set + { + this.currentState.lastLogBackupDate = value; + this.NotifyObservers(); + } + } + /// /// The collation for the database /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs index 4b559d58..54e0dd8f 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs @@ -108,6 +108,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.RecoveryModel, prototype.RecoveryModel.ToString()); databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.IsSystemDB, prototype.IsSystemDB.ToString()); databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.AnsiNulls, prototype.AnsiNulls.ToString()); + databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.CompatibilityLevel, prototype.DatabaseCompatibilityLevel.ToString()); + databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.LastBackupDate, prototype.LastBackupDate.ToString()); + databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.LastLogBackupDate, prototype.LastLogBackupDate.ToString()); databaseInfo.Options.Add( AdminServicesProviderOptionsHelper.FileGroups + "Count", diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs index f589a547..7e5391a5 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs @@ -317,7 +317,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection ServerEdition = serverInfo.ServerEdition, IsCloud = serverInfo.IsCloud, AzureVersion = serverInfo.AzureVersion, - OsVersion = serverInfo.OsVersion + OsVersion = serverInfo.OsVersion, + MachineName = serverInfo.MachineName }; connectionInfo.IsAzure = serverInfo.IsCloud; connectionInfo.MajorVersion = serverInfo.ServerMajorVersion; diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ServerInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ServerInfo.cs index 3bc9e73d..72305180 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ServerInfo.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ServerInfo.cs @@ -59,5 +59,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts /// The Operating System version string of the machine running the SQL Server instance. /// public string OsVersion { get; set; } + + /// + /// The Operating System version string of the machine running the SQL Server instance. + /// + public string MachineName { get; set; } } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/ReliableConnectionHelper.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/ReliableConnectionHelper.cs index 2c190b15..d6348122 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/ReliableConnectionHelper.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/ReliableConnectionHelper.cs @@ -688,6 +688,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection } public string OsVersion; + + public string MachineName; } public static bool TryGetServerVersion(string connectionString, out ServerInfo serverInfo) @@ -751,11 +753,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection serverInfo.ServerVersion = reader[1].ToString(); serverInfo.ServerLevel = reader[2].ToString(); serverInfo.ServerEdition = reader[3].ToString(); + serverInfo.MachineName = reader[4].ToString(); - if (reader.FieldCount > 4) + if (reader.FieldCount > 5) { // Detect the presence of SXI - serverInfo.IsSelectiveXmlIndexMetadataPresent = reader.GetInt32(4) == 1; + serverInfo.IsSelectiveXmlIndexMetadataPresent = reader.GetInt32(5) == 1; } // The 'ProductVersion' server property is of the form ##.#[#].####.#, diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/SqlConnectionHelperScripts.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/SqlConnectionHelperScripts.cs index 421acba8..588b348f 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/SqlConnectionHelperScripts.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/SqlConnectionHelperScripts.cs @@ -7,8 +7,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection { static class SqlConnectionHelperScripts { - public const string EngineEdition = "SELECT SERVERPROPERTY('EngineEdition'), SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition'), (SELECT CASE WHEN EXISTS (SELECT TOP 1 1 from [sys].[all_columns] WITH (NOLOCK) WHERE name = N'xml_index_type' AND OBJECT_ID(N'sys.xml_indexes') = object_id) THEN 1 ELSE 0 END AS SXI_PRESENT)"; - public const string EngineEditionWithLock = "SELECT SERVERPROPERTY('EngineEdition'), SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition'), (SELECT CASE WHEN EXISTS (SELECT TOP 1 1 from [sys].[all_columns] WHERE name = N'xml_index_type' AND OBJECT_ID(N'sys.xml_indexes') = object_id) THEN 1 ELSE 0 END AS SXI_PRESENT)"; + public const string EngineEdition = "SELECT SERVERPROPERTY('EngineEdition'), SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition'), SERVERPROPERTY ('MachineName'), (SELECT CASE WHEN EXISTS (SELECT TOP 1 1 from [sys].[all_columns] WITH (NOLOCK) WHERE name = N'xml_index_type' AND OBJECT_ID(N'sys.xml_indexes') = object_id) THEN 1 ELSE 0 END AS SXI_PRESENT)"; + public const string EngineEditionWithLock = "SELECT SERVERPROPERTY('EngineEdition'), SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition'), SERVERPROPERTY ('MachineName'), (SELECT CASE WHEN EXISTS (SELECT TOP 1 1 from [sys].[all_columns] WHERE name = N'xml_index_type' AND OBJECT_ID(N'sys.xml_indexes') = object_id) THEN 1 ELSE 0 END AS SXI_PRESENT)"; public const string CheckDatabaseReadonly = @"EXEC sp_dboption '{0}', 'read only'";