MSSQL Namespace error

maharshivadapal
Tera Contributor

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.

 

@sukran 

@Sohail Khilji 

 

 

 

6 REPLIES 6

AJ-TechTrek
Giga Sage
Giga Sage

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

maharshivadapal
Tera Contributor

@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?