2017-10-13 157 views
0

我試圖在使用SSIS的電子郵件中發送一組查詢結果。以下是流程的截圖和步驟。嘗試鎖定變量時檢測到死鎖。 16次嘗試後無法獲取鎖定。鎖定超時

截圖:

enter image description here

步驟:1. 使用SQL任務中獲得的 「QueryResult中的」 查詢結果對象變量 2.在foreach循環中使用 「QueryResult中」 對象變量並獲得列值的字符串變量「ProjectRefID」和「賬戶號碼」

enter image description here

3,採用得離譜的foreach循環容器內PT任務以捕獲對象變量「查詢結果」的數據

enter image description here

  • 下面是這是我從複製的腳本任務中的代碼互聯網。

    using System; using System.Data; using Microsoft.SqlServer.Dts.Runtime;使用System.Windows.Forms的 ;

    endregion

    namespace ST_77e6b4ea18824b909adc5568475fcf5c 
    { 
    
        [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute] 
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase 
    
    
    
    { 
    
        public void Main() 
        { 
         Variables varCollection = null; 
         string header = string.Empty; 
         string message = string.Empty; 
    
         Dts.VariableDispenser.LockForWrite("User::ValidationEmailMessage"); 
         Dts.VariableDispenser.LockForRead("User::Accountnumber"); 
         Dts.VariableDispenser.LockForRead("User::ProjectRefID"); 
         Dts.VariableDispenser.GetVariables(ref varCollection); 
    
         if (varCollection["User::ValidationEmailMessage"].Value == string.Empty) 
         { 
          header = "Below are the list of Invalid ProjecRefID and Accountnumbers that are not matching with our existing data:\n\n"; 
          header += string.Format("{0}\t{1}\t\t\t{2}\n", "ProjectRefID", "Accountnumber"); 
          varCollection["User::ValidationEmailMessage"].Value = header; 
          varCollection.Unlock(); 
         } 
    
    
         //Format the query result with tab delimiters 
         message = string.Format("{0}\t{1}\t{2}", 
                varCollection["User::ProjectRefID"].Value, 
                varCollection["User::Accountnumber"].Value); 
    
         varCollection["User::ValidationEmailMessage"].Value = varCollection["User::ValidationEmailMessage"].Value + message; 
         varCollection.Unlock(); 
         Dts.TaskResult = (int)ScriptResults.Success; 
    
        } 
    
    
        enum ScriptResults 
        { 
         Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success, 
         Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure 
        }; 
    
    
    } 
    

    }

  • 我試圖解決這個錯誤,但不知何故,我無法想出解決辦法。讓我知道是否有人知道如何解決它。

    回答

    0

    除非你需要某種原因鎖定功能,你應該能夠簡單地寫了主要方法是:

    public void Main() 
    { 
        string header = string.Empty; 
        string message = string.Empty; 
    
        if (Dts.Variables["User::ValidationEmailMessage"].Value == string.Empty) 
        { 
         header = "Below are the list of Invalid ProjecRefID and Accountnumbers that are not matching with our existing data:\n\n"; 
         header += string.Format("{0}\t{1}\t\t\t{2}\n", "ProjectRefID", "Accountnumber"); 
         Dts.Variables["User::ValidationEmailMessage"].Value = header; 
        } 
    
    
        //Format the query result with tab delimiters 
        message = 
         string.Format("{0}\t{1}\t{2}", 
          Dts.Variables["User::ProjectRefID"].Value, 
          Dts.Variables["User::Accountnumber"].Value); 
    
        Dts.Variables["User::ValidationEmailMessage"].Value = Dts.Variables["User::ValidationEmailMessage"].Value + message; 
    
        Dts.TaskResult = (int)ScriptResults.Success; 
    } 
    

    另外,與你的string.Format代碼,您指定三個指標,{0} ,{1}和{2},但您只提供2個參數,例如,, "ProjectRefID", "Accountnumber");

    相關問題