ExecuteWQL error: An error has occured while accessing WMI: . (Microsoft.SqlServer.Dmf)
-
Wednesday, October 05, 2011 9:29 AM
Hi,
I have a problem using executeWQL for policy based management.
My statement is:ExecuteWql('Numeric', 'root\Microsoft\SqlServer\ComputerManagement', 'SELECT PropertyStrVal FROM ServerNetworkProtocolProperty where PropertyName="TcpPort" and InstanceName="@InstanceName" and IPAddressName="IPAll"')
Error message:An error has occured while accessing WMI: . (Microsoft.SqlServer.Dmf)
Now the problem is that the error does not provide anything useful for solving it. Does anyone has any idea what this can be?
Regards,
Tom
All Replies
-
Friday, October 07, 2011 6:47 AMModerator
Hi Tom,
The problem might be the syntax error of the statement. Do you want to return the port number of the specified SQL Server instance? If that is the case, you can try to use powershell: Get-MSSQL-Port-UsingWMI.
Also, please have a look the contents at end of this article: Working with the WMI Provider for Configuration Management.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Proposed As Answer by Stephanie LvModerator Wednesday, October 12, 2011 12:29 PM
- Unproposed As Answer by TomH000 Monday, October 17, 2011 10:46 AM
-
Monday, October 17, 2011 10:45 AM
Hi Stephanie,
Thanks a lot for looking into my question.
We are actually trying to have a centralized test-set using policy based management, without having to use any extra script-sets. For this reason, powershell is not an option.I have done a few more checks and ruled out the possibility of a syntax error.
___To check the correct syntax, I used the WMI code generator:___
Namespace:
root\Microsoft\SQLServer\ComputerManagementCode:
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\Microsoft\SqlServer\ComputerManagement") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM ServerNetworkProtocolProperty where PropertyName='TcpPort' and InstanceName='POD2008R2_TST' and IPAddressName='IPAll'",,48) For Each objItem in colItems Wscript.Echo "-----------------------------------" Wscript.Echo "ServerNetworkProtocolProperty instance" Wscript.Echo "-----------------------------------" Wscript.Echo "InstanceName: " & objItem.InstanceName Wscript.Echo "IPAddressName: " & objItem.IPAddressName Wscript.Echo "PropertyName: " & objItem.PropertyName Wscript.Echo "PropertyStrVal: " & objItem.PropertyStrVal NextExecuting this code using the WMI code generator, gave a correct output.
After extracting the minimum of necessary code for ExecuteWMI, I retried the policy using the following code in the condition:ExecuteWql('Numeric', 'root\Microsoft\SqlServer\ComputerManagement', 'SELECT PropertyStrVal FROM ServerNetworkProtocolProperty')
It still returned the same error message.
Now, why do I think that the syntax is correctly extracted? I used the sole example to be found of executeWql with the WMI code extractor:
Example: ExecuteWQL('Numeric', 'root\CIMV2', 'select NumberOfProcessors from win32_ComputerSystem')
Example code used with the WMI code extractor:
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_ComputerSystem",,48) For Each objItem in colItems Wscript.Echo "-----------------------------------" Wscript.Echo "Win32_ComputerSystem instance" Wscript.Echo "-----------------------------------" Wscript.Echo "NumberOfProcessors: " & objItem.NumberOfProcessors Next==> My example extracts the same string as namespace and the same part as select-statement.
Now, my guess is that the executewql from object based management does not work with all namespaces. Which I found odd, if I want to use the SQL Server namespaces. Can anyone confirm my suspicion on this or prove me wrong on this?Regards,
Tom
- Proposed As Answer by Ed Price - MSFTMicrosoft Employee, Owner Sunday, December 30, 2012 9:16 AM
- Marked As Answer by Ed Price - MSFTMicrosoft Employee, Owner Thursday, January 10, 2013 4:24 PM

