Skip to content

Get-D365Database - Fix DatabaseName parameter not used for SQL connection#905

Merged
FH-Inway merged 4 commits into
d365collaborative:masterfrom
pavankadabala-png:fix/684-get-d365database-databasename
Jun 21, 2026
Merged

Get-D365Database - Fix DatabaseName parameter not used for SQL connection#905
FH-Inway merged 4 commits into
d365collaborative:masterfrom
pavankadabala-png:fix/684-get-d365database-databasename

Conversation

@pavankadabala-png

Copy link
Copy Markdown
Contributor

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.

@FH-Inway

Copy link
Copy Markdown
Member

@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.
Otherwise, I can fix this, but you would need to merge or rebase your branch with master once the fix is in.

@Splaxi Might be a good idea to run the PR check on a schedule as well to surface such issues earlier.

@FH-Inway

Copy link
Copy Markdown
Member

@Splaxi Regarding the actual change:

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.

Are you ok with this potential breaking change? I don't think it will have any impact. Instead of master, it will now use AxDB as default. So this would only impact people that have access to master, but not to AxDB, which seems highly unlikely.

@pavankadabala-png

Copy link
Copy Markdown
Contributor Author

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.

@FH-Inway FH-Inway merged commit 13893f8 into d365collaborative:master Jun 21, 2026
5 checks passed
@FH-Inway

Copy link
Copy Markdown
Member

Thanks for the fixes and the contribution overall. I will make a comment in the issue once a version with this has been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get-D365Database has an unused parameter ($DatabaseName)

2 participants