-
-
Notifications
You must be signed in to change notification settings - Fork 854
Export-DbaDacPackage - Add thread-safe database enumeration and SQL Server version check #9981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…erver version check - Replace SMO-based Get-DbaDatabase with T-SQL query using Invoke-DbaQuery - Fixes thread-safety issues in parallel PowerShell runspaces (100% vs 26.7% success) - Add SQL Server 2008 R2+ (Version 10.50) minimum version validation - Update documentation to reflect DAC Framework requirements Fixes #9980 (do Export-DbaDacPackage) Co-authored-by: Chrissy LeMaire <[email protected]>
Code Review: Export-DbaDacPackage Thread-Safety FixThank you for this PR! The thread-safety fix addresses a critical issue with parallel execution. I've reviewed the changes against the dbatools style guide and have the following feedback: ✅ Strengths
|
|
@claude fix it all |
|
Claude finished @potatoqualitee's task —— View job All Fixes Implemented ✅Successfully implemented all 4 code review fixes:
Summary of Changes1. SQL Injection Fix (Critical) # Before (vulnerable):
$excludedDatabaseList = $ExcludeDatabase | ForEach-Object { "'$_'" }
$query += "`n AND name NOT IN ($($excludedDatabaseList -join ","))"
# After (secure):
$sqlParams = @{}
if ($ExcludeDatabase) {
$placeholders = @()
for ($i = 0; $i -lt $ExcludeDatabase.Count; $i++) {
$placeholders += "@exclude$i"
$sqlParams["exclude$i"] = $ExcludeDatabase[$i]
}
$query += "`n AND name NOT IN ($($placeholders -join ','))"
}2. Splat Usage (Style Guide Compliance) $splatQuery = @{
SqlInstance = $server
Query = $query
EnableException = $true
}
if ($sqlParams.Count -gt 0) {
$splatQuery.SqlParameter = $sqlParams
}
$dbNames = Invoke-DbaQuery @splatQuery | Select-Object -ExpandProperty name3. Documentation Formatting 4. Error Message Spacing Testing Recommendations
All changes follow the dbatools CLAUDE.md style guide and maintain PowerShell v3 compatibility. --- | |
…code review suggestions - Replace string concatenation with parameterized queries for ExcludeDatabase filter - Add splat for Invoke-DbaQuery calls with 3+ parameters per style guide - Remove extra blank line in .NOTES section for consistent formatting - Fixes SQL injection vulnerability where malicious database names could be executed (do Export-DbaDacPackage) Co-authored-by: Chrissy LeMaire <[email protected]>
|
Tests pass 👍🏼 |
Summary
This PR implements a thread-safety fix for
Export-DbaDacPackageto resolve critical issues when running in parallel PowerShell runspaces.Changes
Get-DbaDatabasewith T-SQL query usingInvoke-DbaQueryProblem
When using
Export-DbaDacPackagein parallel runspaces, the function failed with "Databases not found" errors on 73-94% of servers due to SMO thread-safety issues. The original implementation usedGet-DbaDatabasewhich relies on SMO's$server.Databasescollection - SMO objects are NOT thread-safe.Solution
Replace SMO-based database enumeration with T-SQL query-based enumeration. This eliminates SMO object sharing across runspaces while maintaining identical functionality.
Testing Evidence
Fixes #9980
Generated with Claude Code