MSSQL Namespace error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
While working on discovery I am getting the following error message
Error during execution of Windows command: executeQuery -Namespace root/Microsoft/SqlServer -Query "SELECT Name FROM __NAMESPACE" due to com.snc.automation_common.integration.exceptions.InvalidCommandException: executeQuery : Could not get query SELECT Name FROM __NAMESPACE on namespace=root/Microsoft/SqlServer. Original Exception: Invalid namespace.
Can anyone in the community help with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @maharshivadapal ,
This "Invalid namespace" error in ServiceNow Discovery for Windows/SQL Server means the WMI namespace youāre trying to query (root/Microsoft/SqlServer) doesnāt exist on the target server.
As per my understanding why this happens
1. The namespace root/Microsoft/SqlServer is version-specific ā itās not present on all Windows hosts.
2. SQL Server installs WMI namespaces differently depending on:
* SQL Server version
* SQL Server feature set installed (e.g., Database Engine, SSRS, SSAS)
* Whether WMI Provider for SQL Server is enabled
3. If SQL Server isnāt installed, or the SQL Server WMI Provider isnāt installed/enabled, the namespace will be missing.
4. In some cases, SQL Server instances use versioned namespaces like:
* root\Microsoft\SqlServer\ComputerManagement
* root\Microsoft\SqlServer\ComputerManagement14 (for SQL Server 2017)
* root\Microsoft\SqlServer\ComputerManagement15 (for SQL Server 2019)
* root\Microsoft\SqlServer\ComputerManagement16 (for SQL Server 2022)
How to Fix in ServiceNow Discovery
1. Verify Namespace on the Target Machine
On the target Windows server:
Get-WmiObject -Namespace "root\Microsoft\SqlServer" -List
Or for versioned namespaces:
Get-WmiObject -Namespace "root\Microsoft\SqlServer\ComputerManagement*" -List
If it returns Invalid namespace, SQL Server WMI provider is missing or the path is wrong.
2. Update the Discovery Pattern/Probe
* In ServiceNow Patterns:
1. Open the SQL Server pattern or MS SQL Server probe.
2. Replace the hardcoded namespace with a conditional step that checks for available namespaces.
3. Example:āØ$namespaces = @(
"root\Microsoft\SqlServer\ComputerManagement16",
"root\Microsoft\SqlServer\ComputerManagement15",
"root\Microsoft\SqlServer\ComputerManagement14",
"root\Microsoft\SqlServer\ComputerManagement",
"root\Microsoft\SqlServer"
)
foreach ($ns in $namespaces) {
try {
Get-WmiObject -Namespace $ns -List | Out-Null
Write-Host "Using namespace: $ns"
break
} catch {}
}
* This ensures the discovery picks the correct version-specific namespace.
3, Install/Enable WMI Provider for SQL Server (If Missing)
* On the target server:
* Open SQL Server installer ā Modify ā Management Tools ā Enable WMI Provider for SQL Server.
* Or install via command line:āØsetup.exe /q /ACTION=Install /FEATURES=SQL,Tools
* Restart WMI service after installation:āØnet stop winmgmt /y
* net start winmgmt
4. Adjust ServiceNow Probe Timeout/Retry
If the namespace exists but intermittently fails, increase the timeout in the Windows - WMI Class List probe or ensure DCOM/WMI permissions are correct for the Discovery account.
Please appreciate the efforts of community contributors by marking appropriate response as Mark my Answer Helpful or Accept Solution this may help other community users to follow correct solution in future.
Thank You
AJ - TechTrek with AJ - ITOM Trainer
LinkedIn:- https://www.linkedin.com/in/ajay-kumar-66a91385/
YouTube:- https://www.youtube.com/@learnitomwithaj
Topmate:- https://topmate.io/aj_techtrekwithaj (Connect for 1-1 Session)
ServiceNow Community MVP 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@AJ-TechTrekHi, I tried following the steps for changes in the pattern designer code you provided, but when I attempt to save, it keeps saving the original code instead of my changes. Could you please help me with this?