Skip to content

Commit c4e5109

Browse files
Merge pull request #82 from microsoft/20241204_DriveInfoExceptionHandling
Disk Drive exception handling
2 parents 7e8dbcd + abf81c2 commit c4e5109

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed
0 Bytes
Binary file not shown.

SQLCheck/SQLCheck/Collectors.cs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,21 +1128,35 @@ public static void CollectDiskDrive(DataSet ds)
11281128

11291129
int pctFree = 0;
11301130

1131-
foreach (DriveInfo drive in DriveInfo.GetDrives())
1131+
try
11321132
{
1133-
DataRow DiskDrive = ds.Tables["DiskDrive"].NewRow();
1134-
DiskDrive["Drive"] = drive.Name;
1135-
DiskDrive["DriveType"] = drive.DriveType.ToString();
1136-
if (drive.IsReady)
1133+
foreach (DriveInfo drive in DriveInfo.GetDrives())
11371134
{
1138-
DiskDrive["DriveFormat"] = drive.DriveFormat;
1139-
DiskDrive["Capacity"] = drive.TotalSize.ToString("#,##0");
1140-
DiskDrive["BytesFree"] = drive.TotalFreeSpace.ToString("#,##0");
1141-
pctFree = (int)((drive.TotalFreeSpace * 100.0) / drive.TotalSize);
1142-
DiskDrive["PctFree"] = $"{pctFree}%";
1143-
if (pctFree < 10) DiskDrive["Message"] = "Low Disk Space";
1135+
DataRow DiskDrive = ds.Tables["DiskDrive"].NewRow();
1136+
try
1137+
{
1138+
ds.Tables["DiskDrive"].Rows.Add(DiskDrive);
1139+
DiskDrive["Drive"] = drive.Name;
1140+
DiskDrive["DriveType"] = drive.DriveType.ToString();
1141+
if (drive.IsReady)
1142+
{
1143+
DiskDrive["DriveFormat"] = drive.DriveFormat;
1144+
DiskDrive["Capacity"] = drive.TotalSize.ToString("#,##0");
1145+
DiskDrive["BytesFree"] = drive.TotalFreeSpace.ToString("#,##0");
1146+
pctFree = (int)((drive.TotalFreeSpace * 100.0) / drive.TotalSize);
1147+
DiskDrive["PctFree"] = $"{pctFree}%";
1148+
if (pctFree < 10) DiskDrive["Message"] = "Low Disk Space";
1149+
}
1150+
}
1151+
catch (Exception ex)
1152+
{
1153+
DiskDrive.LogException("Error reading disk drive properties.", ex);
1154+
}
11441155
}
1145-
ds.Tables["DiskDrive"].Rows.Add(DiskDrive);
1156+
}
1157+
catch (Exception ex2)
1158+
{
1159+
Computer.LogException("Error enumerating disk drives.", ex2);
11461160
}
11471161
}
11481162

SQLCheck/SQLCheck/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("Microsoft Corporation - SQL Server Customer Support")]
1212
[assembly: AssemblyProduct("SQLCheck")]
13-
[assembly: AssemblyCopyright("Copyright © 2021, 2022, 2023, 2024")]
13+
[assembly: AssemblyCopyright("Copyright © 2021, 2022, 2023, 2024, 2025")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.1437.0")]
36-
[assembly: AssemblyFileVersion("1.0.1437.0")]
35+
[assembly: AssemblyVersion("1.0.1438.0")]
36+
[assembly: AssemblyFileVersion("1.0.1438.0")]

0 commit comments

Comments
 (0)