码迷,mamicode.com
首页 > 其他好文 > 详细

SSIS Memory is locked 和 RegEx

时间:2015-11-06 18:05:24      阅读:845      评论:0      收藏:0      [点我收藏+]

标签:

 在运行package时,如果package中使用Script component,那么有时能看到以下错误信息:

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)

 

在Package中使用Script component的情况,一般是使用正则表达式处理字符串数据,在我的package中,存在RegEx对象,测试表明,RegEx存在memory leak的bug,分析过程,请查看参考文档中引用的文档

 

    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:

由于Input0_ProcessInputRow 的调用次数和数据行数相同,所以可以将下面两段代码放到PreExecute函数中,避免频繁创建Regex对象,并在class scope中创建Regex regex字段。

string spattern = @"(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?";

regex = new Regex(spattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);

 

参考文档:

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 和 RegEx

标签:

原文地址:http://www.cnblogs.com/ljhdo/p/4932350.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!