我想在有文件放入特定文件夾時執行作業。使用WMI的SQL Server警報事件錯誤
我發現了一些文章,告訴我如何在SQL Server上做到這一點。
我創建了一個警報類型:WMI Event Alert
對於名稱空間的SQL實例自動當屬\\.\root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER
在查詢部分 - 我寫了下面的查詢,
SELECT *
FROM __InstanceCreationEvent
WITHIN 1
WHERE TargetInstance ISA 'CIM_DataFile'
AND TargetInstance.Name = ‘c:\\TestFolder\’ `
返回的錯誤消息是:
Cannot create new alert.
ADDITIONAL INFORMATION:
Create failed for Alert 'AlertTest'. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.2425.0+((KJ_PCU_Main).110406-2044+)&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錯誤:WMI error: 0x80041058
@wmi_query
的不能在所提供的@wmi_namespace
被執行。驗證查詢中選擇的事件類是否存在於命名空間中,並且查詢是否具有正確的語法。 (微軟SQL服務器,錯誤:22022)
請您可以告知,如果我的查詢是正確的,如果有什麼事我需要檢查?
非常感謝。
你好,你的儀式。我用下面的查詢,並得到了這個工作 - 非常感謝 - 命名空間是錯誤的 EXEC msdb.dbo.sp_add_alert @名稱= N'SimpleFolderWatcher」, \t \t @ MESSAGE_ID = 0, \t \t @嚴重性= 0, \t \t @啓用= 1, \t \t @ delay_between_responses = 0, \t \t @ include_event_description_in = 0, \t \t @ CATEGORY_NAME = N '[未歸類]', \t \t @ wmi_namespace = N'\\。\根\ CIMV2' , \t \t @ wmi_query = N'SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA '' CIM_DataFile '' AND TargetInstance.Drive = '' C: '' AND TargetInstance.Path = '' \\ \\ testfolder' 和TargetInstance.Name LIKE'C:\\% ''」, \t \t @ JOB_ID = N'0-0-0' GO – Shan
@Shan,OK,很高興幫您。不要忘記接受答案。 – RRUZ