2014-06-06 10 views
0

SSIS에서 수행하려는 작업에는 WMI 이벤트 감시자 작업이 있으며이 태스크는 파일을 만들 폴더를 감시 한 다음 해당 작업을 수행합니다. 주요 부분은 "파일 생성을위한 폴더보기"입니다.SSIS WMI 이벤트 감시자는 네트워크 폴더를 쿼리합니까?

내가 네트워크 폴더 (전체 경로)가 : 나는 갔어요 \\srvblah10\main\child\target\

모든 사이트에이이 예를 들어 :

SELECT * FROM __InstanceCreationEvent WITHIN 10 
WHERE TargetInstance ISA "CIM_DirectoryContainsFile" 
AND TargetInstance.GroupComponent = "Win32_Directory.Name=\"d:\\\\NewFiles\"" 

폴더가 네트워크 폴더이기 때문에, 내가 할 수있는 물리적 디스크 문자를 제공하지 않습니다. 그렇다면 비슷한 WQL 쿼리를 사용하는 방법이 있지만 실제 폴더 경로가 아닌 네트워크 폴더 경로가 필요합니까?

답변

0

당신은 도스 명령으로 드라이브를 매핑 할 수 있습니다 인터넷 사용의 : \ srvblah10 주요 \ 자식 \ 대상 \ \/사용자 dotnetN00b 아빠 $$ 단어

당신이 그것을 볼 수있는 WMI Event Watcher Task 수 있습니다.

0

잠시 동안이 작업을 시도하고 SSIS WMI 이벤트 감시자 작업을 사용하려고 시도했지만 결국 스크립트 작업에서 해당 작업을 작성했습니다. 문제는 WMI Event Watcher가 구성 섹션 (하드 코드가 아닌 패키지)에서 얻으려는 특정 사용자 자격 증명을 사용하여 원격 연결을 설정하는 것이 었습니다.

스크립트를 사용하지 않는 두 번째 문제는 단순히 네트워크 공유를 이벤트 감시자가 필요로하는 서버의 로컬 경로 이름으로 변환하는 것이 었습니다. 아래 그림에서 볼 수 있듯이 모든 것이 최소한의 노력으로 완성됩니다.

스크립트가 ReadOnlyVariables에 사용하는 DTS.Variables를 포함시켜야합니다 (정상적으로). 당신이 코페르니쿠스의 \의 하차의 \의 SAP \ \ 다음 위치 에 낙하 파일을 감시하려는 경우 아래의 코드는, 예를 들어, 세 개의 DTS 변수를 필요로 가져 오기는 다음 변수를 설정합니다 아래와 같이

  • 사용자 : 서버 이름 - 네트워크 공유의 이름 ( 하차)
  • - 공유가 ( 코페르니쿠스)
  • 사용자 : 공유 이름을 사는 서버의 호스트 이름 6,
  • 사용자 : ImportPath - 새로운 파일에 대한 시계에 대한 디렉토리의 디렉토리 경로 (/SAP/가져 오기)


public void Main() 
{ 
string localPath = ""; 

    try 
    { 
     ConnectionOptions connection = new ConnectionOptions(); 
     connection.Username = "<valid username here>"; 
     connection.Password = "<password here>"; 
     connection.Authority = "ntlmdomain:<your domain name here>"; 

     ManagementScope scope = new ManagementScope(@"\\" + Dts.Variables["User::FileServerName"].Value.ToString() + @"\root\CIMV2", connection); 
     scope.Connect(); 

     /// Retrieve the local path of the network share from the file server 
     /// 
     string queryStr = string.Format("SELECT Path FROM Win32_Share WHERE Name='{0}'", Dts.Variables["User::ShareName"].Value.ToString()); 
     ManagementObjectSearcher mosLocalPath = new ManagementObjectSearcher(scope, new ObjectQuery(queryStr)); 
     foreach (ManagementObject elements in mosLocalPath.Get()) 
     { 
      localPath = elements["Path"].ToString(); 
     } 

     queryStr = string.Format(
      "SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent=\"Win32_Directory.Name='{0}{1}'\"", 
      localPath.Replace(@"\", @"\\"), 
      Dts.Variables["User::ImportPath"].Value.ToString().Replace(@"\", @"\\")); // query requires each seperator to be a double back slash 

     ManagementEventWatcher watcher = new ManagementEventWatcher(scope, new WqlEventQuery(queryStr)); 

     ManagementBaseObject eventObj = watcher.WaitForNextEvent(); 

     // Cancel the event subscription 
     watcher.Stop(); 

     Dts.TaskResult = (int)ScriptResults.Success; 
    } 
    catch (ManagementException err) 
    { 
     Dts.Events.FireError((int)err.ErrorCode, "WMI File Watcher", "An error occurred while trying to receive an event: " + err.Message, String.Empty, 0); 
     Dts.TaskResult = (int)ScriptResults.Failure; 
    } 
    catch (System.UnauthorizedAccessException unauthorizedErr) 
    { 
     Dts.Events.FireError((int)ManagementStatus.AccessDenied, "WMI File Watcher", "Connection error (user name or password might be incorrect): " + unauthorizedErr.Message, String.Empty, 0); 
     Dts.TaskResult = (int)ScriptResults.Failure; 
    } 

}