SSIS Memory is locked and RegEx

Source: Internet
Author: User
Tags ssis



When you run the package, you can sometimes see the following error message if you use Script component in the package:



System.Runtime.InteropServices.COMException (0x8002000d): Memory is locked. (Exception from hresult:0x8002000d (disp_e_arrayislocked))
At Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException (Exception e)
At Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput (Int32 inputID, PipelineBuffer buffer)
At Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostProcessInput (IDTSManagedComponentWrapper100 Wrapper , Int32 inputID, IDTSBuffer100 pdtsbuffer, IntPtr bufferwirepacket)






In the case of using Script component in the package, it is generally the use of regular expressions to process string data, in my package, there is a Regex object, the test shows that the regex has memory leak bug, the analysis process, Please see the documentation referenced in the reference document





  

   public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        byte[] source = Row.Body.GetBlobData(0, (int)Row.Body.Length);
        string sinput = Encoding.Unicode.GetString(source, 0, source.Length);
        string spattern = @"(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?";

        List<string> returns = new List<string>();

        try
        {
            Regex regex = new Regex(spattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            var values = regex.Matches(sinput);

            if (values != null && values.Count > 0)
            {
            //----------
            }
        }
        catch
        {

        }
    }


Scenario Follow:



Because Input0_processinputrow has the same number of calls and rows of data, you can put the following two pieces of code into the PreExecute function, avoid creating regex objects frequently, and create a Regex regex field in class scope.



String spattern = @ "(HTTP|FTP|HTTPS): \/\/[\w\-_]+ (\.[ \w\-_]+) + ([\w\-\.,@?^=%&amp;:/ ~\+#]*[\w\-\@?^=%&amp;/~\+#])? ";



Regex = New Regex (Spattern, regexoptions.ignorecase | Regexoptions.multiline);






Reference Documentation:



http://blogs.msdn.com/b/bclteam/archive/2006/10/19/ Regex-class-caching-changes-between-net-framework-1-1-and-net-framework-2-0-josh-free.aspx



Http://stackoverflow.com/questions/11174366/c-sharp-memory-leak



Http://stackoverflow.com/questions/2734766/net-regex-memory-leak-investigation



SSIS Memory is locked and RegEx


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.