After installing SQL Server 2005, I tried to create a WMI alert by doing the following:
USE [msdb]
GO
EXEC msdb.dbo.sp_add_alert @name=N'Database Created',
@enabled=1,
@delay_between_responses=0,
@include_event_description_in=0,
@wmi_namespace=N'\\.\root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER',
@wmi_query=N'SELECT * FROM CREATE_DATABASE',
@job_id=N'00000000-0000-0000-0000-000000000000'
GO
This produces:
"The @wmi_query could not be executed in the @wmi_namespace provided.
Verify that an event class selected in the query exists in the
namespace and that the query has the correct syntax."
Now, I have done the install many times on a VM box and believe to have tracked it down to moving the msdb database. The alerts can be created, but after the move, I get the above error.
To move the db, I used sp_detach_db after adding the -T3608 trace flag. I then moved the .mdf and .ldf files, then removed the trace flag and reattached msdb.
Any ideas as to what the problem is

WMI alerting error
RWeigelt
Has anyone figured out how to fix this problem I also receive the same error and I did not move msdb, it still sits in the default location on c:\, all other databases are off the system drive. We are somewhere along the chain of SP2 updates, I believe SP2a before hotfixes.
Any help would be greatly appreciated.
Ori234454
I am trying to setup the alerts according the article published on http://www.microsoft.com/technet/prodtechnol/sql/2005/mirroringevents.mspx in the chapter "Script Sample - Create Alerts for All Database Mirroring Events"
I ran the script on the priciplal server running SQL 2005 SP2 (9.00.3159.00)
I am grtting the errors below:
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Thanks,
Vlad
Ruben S Salazar
Surfertje
In general, sp_detach_db and sp_attach_db is NOT recommended way to move a system database.
Our test team validated this scenario by using the recommended way to move database (see topic “Moving Database Files
” in BOL) and it works fine.There was no problem with sp_add_alert once msdb was moved.
The steps followed
1. determine the logical name of the database and current location of physical files
SELECT name AS [logical name], physical_name AS [location]
FROM sys.master_files
WHERE database_id = DB_ID('msdb')
2. change the location of each file from the step 1
--ALTER DATABASE msdb
--MODIFY FILE (NAME = <logical_name>, FILENAME = <new_location\file_name>)
USE master;
GO
ALTER DATABASE msdb
MODIFY FILE (NAME = MSDBData, FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\msdbdata.mdf');
GO
ALTER DATABASE msdb
MODIFY FILE (NAME = MSDBLog, FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\msdblog.ldf');
GO
3. stop SQL Server
4. move each file from the step 1 to the new location
5. start SQL Server
sewe
This looks like a bug. Please file bug for us to track this issue at product feedback center
http://lab.msdn.microsoft.com/productfeedback/
Thanks
prigun
Justin Niemetscheck
I am too having this problem, i have not moved my MSDB or any other DB's. This is a Build 3042 SP2 box, has anyone seen a work around or hotfix
Thanks,
jkuster
I too am getting this error. We are running sp1.
TITLE: Microsoft SQL Server Management Studio
------------------------------
Cannot create new alert. (SqlManagerUI)
------------------------------
ADDITIONAL INFORMATION:
Create failed for Alert 'test'. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink ProdName=Microsoft+SQL+Server&ProdVer=9.00.2047.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+Alert&LinkId=20476
------------------------------
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
SQLServerAgent Error: WMI error: 0x80041010.
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax. (Microsoft SQL Server, Error: 22022)
For help, click: http://go.microsoft.com/fwlink ProdName=Microsoft+SQL+Server&ProdVer=09.00.2153&EvtSrc=MSSQLServer&EvtID=22022&LinkId=20476
------------------------------
BUTTONS:
OK
------------------------------
vccool
If you want to move the sys.databases then above suggestion to stop and start SQL services, not to reinstall the whole components.
I would like to know what was your problem
Tim Haynes
santosh k singh
anayconsultancy
I found out what was causing my error. I am in the process of deploying DB mirroring, i was running the sp_add_alert against the syncronising DB on the mirror server that is in a recovery mode.(doh)..so the alert could not be verified and errored that the namespace could be wrong.
I also did think it maybe a security issue, using WBEMTest tool to check the security will help..WillRogers
So I tested this by creating a WMI Alert on a fresh install of SQL Server 2005 and it was created successfully.
So I delete the alert, backed up the MSDB and restored it.
Now when I try to create a WMI alerts, I get this error message
"The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax."
Conclusion:
It seems if you restore MSDB it will break WMI Alerts.
Brenden
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.
Msg 22022, Level 16, State 1, Line 0
SQLServerAgent Error: WMI error: 0x80041013.
Msg 14511, Level 16, State 1, Procedure sp_verify_alert, Line 300
The @wmi_query could not be executed in the @wmi_namespace provided. Verify that an event class selected in the query exists in the namespace and that the query has the correct syntax.