Get-D365Database - Fix DatabaseName parameter not used for SQL connection#905
Conversation
|
@pavankadabala-png I've been looking into why the PR check fails. Turns out, the PSScriptAnalyzer got a new version and we have not run the check action since then. Part of the new version was PowerShell/PSScriptAnalyzer#2121, which fixed some issues in the checks for AvoidDefaultValueForMandatoryParameter. So now this check finds some issues that have existed in d365fo.tools for a long time. Would you like to take a stab at those issues as well? Seems a simple fix, just two default values of mandatory parameters that need to be removed. Documentation needs to be changed accordingly. @Splaxi Might be a good idea to run the PR check on a schedule as well to surface such issues earlier. |
|
@Splaxi Regarding the actual change:
Are you ok with this potential breaking change? I don't think it will have any impact. Instead of |
|
Happy to take care of those in this PR — I'll address the PSScriptAnalyzer findings and push an updated commit. Give me a day or two and I'll let you know when it's ready for another look. |
|
Thanks for the fixes and the contribution overall. I will make a comment in the issue once a version with this has been released. |
Summary
Fixes #684
Get-D365Database accepts a -DatabaseName parameter (defaulting to the database configured via the module's connection config), but this value was never passed into $SqlParams - the SQL connection was always opened against the hardcoded "master" database, regardless of -DatabaseName. This breaks setups where the SQL credentials only have access to a specific database (and not master).
Changes
$SqlParams.DatabaseName now uses $DatabaseName instead of the hardcoded "master" string, so the connection is opened against the requested/configured database. The .PARAMETER DatabaseName comment-based help has been expanded to explain its purpose, use case, and default value, and a new .EXAMPLE demonstrates Get-D365Database -DatabaseName AXDB.
Notes
sys.databases is a server-scoped catalog view and remains queryable from any database context, so the existing -Name output filter is unaffected. Callers relying on the previous (unintentional) master-only connection behavior may need to pass -DatabaseName master explicitly going forward; this aligns the function's behavior with its documented parameter.