Skip to content

Commit 902f23b

Browse files
Get-DbaDb[StoredProcedure|Table|Udf|View]: Wrap all ClearAndInitialize in try-catch-block (#10226)
1 parent f2fb478 commit 902f23b

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

public/Get-DbaDbStoredProcedure.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ function Get-DbaDbStoredProcedure {
185185

186186
# Let the SMO read all properties referenced in this command for all stored procedures in the database in one query.
187187
# Downside: If some other properties were already read outside of this command in the used SMO, they are cleared.
188-
$db.StoredProcedures.ClearAndInitialize('', [string[]]('Schema', 'Name', 'ID', 'CreateDate', 'DateLastModified', 'ImplementationType', 'Startup', 'IsSystemObject'))
188+
try {
189+
$db.StoredProcedures.ClearAndInitialize('', [string[]]('Schema', 'Name', 'ID', 'CreateDate', 'DateLastModified', 'ImplementationType', 'Startup', 'IsSystemObject'))
190+
} catch {
191+
Write-Message -Level Verbose -Message "ClearAndInitialize failed: $_"
192+
}
189193

190194
if ($db.StoredProcedures.Count -eq 0) {
191195
Write-Message -Message "No Stored Procedures exist in the $db database on $instance" -Target $db -Level Output

public/Get-DbaDbTable.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ function Get-DbaDbTable {
284284
}
285285
}
286286

287-
$db.Tables.ClearAndInitialize($urnFilter, [string[]]$properties)
287+
try {
288+
$db.Tables.ClearAndInitialize($urnFilter, [string[]]$properties)
289+
} catch {
290+
Write-Message -Level Verbose -Message "ClearAndInitialize failed: $_"
291+
}
288292

289293
if ($fqTns) {
290294
$tables = @()

public/Get-DbaDbUdf.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,18 @@ function Get-DbaDbUdf {
151151

152152
# Let the SMO read all properties referenced in this command for all user defined functions in the database in one query.
153153
# Downside: If some other properties were already read outside of this command in the used SMO, they are cleared.
154-
$db.UserDefinedFunctions.ClearAndInitialize('', [string[]]('Schema', 'Name', 'CreateDate', 'DateLastModified', 'DataType', 'IsSystemObject'))
154+
try {
155+
$db.UserDefinedFunctions.ClearAndInitialize('', [string[]]('Schema', 'Name', 'CreateDate', 'DateLastModified', 'DataType', 'IsSystemObject'))
156+
} catch {
157+
Write-Message -Level Verbose -Message "ClearAndInitialize failed: $_"
158+
}
155159

156160
# UserDefinedAggregates don't have IsSystemObject property, so initialize separately
157-
$db.UserDefinedAggregates.ClearAndInitialize('', [string[]]('Schema', 'Name', 'CreateDate', 'DateLastModified', 'DataType'))
161+
try {
162+
$db.UserDefinedAggregates.ClearAndInitialize('', [string[]]('Schema', 'Name', 'CreateDate', 'DateLastModified', 'DataType'))
163+
} catch {
164+
Write-Message -Level Verbose -Message "ClearAndInitialize failed: $_"
165+
}
158166

159167
$userDefinedFunctions = $db.UserDefinedFunctions
160168

public/Get-DbaDbView.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ function Get-DbaDbView {
164164

165165
# Let the SMO read all properties referenced in this command for all views in the database in one query.
166166
# Downside: If some other properties were already read outside of this command in the used SMO, they are cleared.
167-
$db.Views.ClearAndInitialize('', [string[]]('Name', 'Schema', 'IsSystemObject', 'CreateDate', 'DateLastModified'))
167+
try {
168+
$db.Views.ClearAndInitialize('', [string[]]('Name', 'Schema', 'IsSystemObject', 'CreateDate', 'DateLastModified'))
169+
} catch {
170+
Write-Message -Level Verbose -Message "ClearAndInitialize failed: $_"
171+
}
168172

169173
if ($fqtns) {
170174
$views = @()

0 commit comments

Comments
 (0)