mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Fixing GetServerSystemInfo for Azure DBs (#1231)
* Not throwing errors when we try to fetch SQL server properties like server count and physical mem. * Fixed comment * Renaming get server cpu count * Adding more detailed comment over here * Making properties cpu count and physical memory to nullable<int> so they are defaulted to null. * Fixing rest of the properties to nullable.
This commit is contained in:
@@ -653,8 +653,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
|||||||
public string OsVersion;
|
public string OsVersion;
|
||||||
public string MachineName;
|
public string MachineName;
|
||||||
public string ServerName;
|
public string ServerName;
|
||||||
public int CpuCount;
|
public Nullable<int> CpuCount;
|
||||||
public int PhysicalMemoryInMB;
|
public Nullable<int> PhysicalMemoryInMB;
|
||||||
public Dictionary<string, object> Options { get; set; }
|
public Dictionary<string, object> Options { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,8 +678,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
|||||||
|
|
||||||
public class ServerSystemInfo
|
public class ServerSystemInfo
|
||||||
{
|
{
|
||||||
public int CpuCount;
|
public Nullable<int> CpuCount;
|
||||||
public int PhysicalMemoryInMB;
|
public Nullable<int> PhysicalMemoryInMB;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryGetServerVersion(string connectionString, out ServerInfo serverInfo, string azureAccountToken)
|
public static bool TryGetServerVersion(string connectionString, out ServerInfo serverInfo, string azureAccountToken)
|
||||||
@@ -763,7 +763,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
|||||||
/// Gets the server host cpu count and memory from sys.dm_os_sys_info view
|
/// Gets the server host cpu count and memory from sys.dm_os_sys_info view
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connection">The connection</param>
|
/// <param name="connection">The connection</param>
|
||||||
public static ServerSystemInfo GetServerSystemInfo(IDbConnection connection)
|
public static ServerSystemInfo GetServerCpuAndMemoryInfo(IDbConnection connection)
|
||||||
{
|
{
|
||||||
var sysInfo = new ServerSystemInfo();
|
var sysInfo = new ServerSystemInfo();
|
||||||
try
|
try
|
||||||
@@ -776,8 +776,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
// We don't want to fail the normal flow if any unexpected thing happens
|
||||||
|
// since these properties are not available for types of sql servers and users
|
||||||
|
// and it is not essential to always include them
|
||||||
|
// just logging the errors here and moving on with the workflow.
|
||||||
Logger.Write(TraceEventType.Error, ex.ToString());
|
Logger.Write(TraceEventType.Error, ex.ToString());
|
||||||
throw ex;
|
|
||||||
}
|
}
|
||||||
return sysInfo;
|
return sysInfo;
|
||||||
}
|
}
|
||||||
@@ -856,7 +859,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
|||||||
// otherwise - Windows Server 2019 Standard 10.0
|
// otherwise - Windows Server 2019 Standard 10.0
|
||||||
serverInfo.OsVersion = hostInfo.Distribution != null ? string.Format("{0} {1}", hostInfo.Distribution, hostInfo.Release) : string.Format("{0} {1}", hostInfo.Platform, hostInfo.Release);
|
serverInfo.OsVersion = hostInfo.Distribution != null ? string.Format("{0} {1}", hostInfo.Distribution, hostInfo.Release) : string.Format("{0} {1}", hostInfo.Platform, hostInfo.Release);
|
||||||
|
|
||||||
var sysInfo = GetServerSystemInfo(connection);
|
var sysInfo = GetServerCpuAndMemoryInfo(connection);
|
||||||
|
|
||||||
serverInfo.CpuCount = sysInfo.CpuCount;
|
serverInfo.CpuCount = sysInfo.CpuCount;
|
||||||
serverInfo.PhysicalMemoryInMB = sysInfo.PhysicalMemoryInMB;
|
serverInfo.PhysicalMemoryInMB = sysInfo.PhysicalMemoryInMB;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||||
@@ -70,12 +71,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The CPU count of the host running the server.
|
/// The CPU count of the host running the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int CpuCount;
|
public Nullable<int> CpuCount;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The physical memory of the host running the server in MBs.
|
/// The physical memory of the host running the server in MBs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int PhysicalMemoryInMB;
|
public Nullable<int> PhysicalMemoryInMB;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Server options
|
/// Server options
|
||||||
|
|||||||
Reference in New Issue
Block a user