1

HASHBYTE ロジックを処理するコードの次のセクションでエラーが発生します。

<ScriptComponentTransformation Name ="SCR HashByte Data Thread 1">

<ScriptComponentProject>
<ScriptComponentProject Name="SCRHashByteDataThread1">

<AssemblyReferences>
<AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSPipelineWrap" />
<AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSRuntimeWrap" />
<AssemblyReference AssemblyPath="Microsoft.SqlServer.PipelineHost" />
<AssemblyReference AssemblyPath="Microsoft.SqlServer.TxScript" />
<AssemblyReference AssemblyPath="System.dll" />
<AssemblyReference AssemblyPath="System.AddIn.dll" />
<AssemblyReference AssemblyPath="System.Data.dll" />
<AssemblyReference AssemblyPath="System.Xml.dll" />
</AssemblyReferences>

<InputBuffer Name="Input0">
<Columns>
<Column Name="RowNumber" DataType ="Int64" UsageType ="ReadWrite"></Column>
</Columns>
</InputBuffer>

<OutputBuffers>

<OutputBuffer Name="Output0">
<Columns>
<Column Name="MD5" DataType ="AnsiStringFixedLength"></Column>
</Columns>
</OutputBuffer>
</OutputBuffers>

<Files>
<File Path ="AssemblyInfo.cs">
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("SC_AddRowNumber")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SC_AddRowNumber")]
[assembly: AssemblyCopyright("Copyright @ Homeserve 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.*")]

</File>



<File Path ="main.cs">
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Text;
using System.IO;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    private System.Security.Cryptography.MD5 _md5 =new System.Security.Cryptography.MD5CryptoServiceProvider();

    public override void PreExecute()
    {
        base.PreExecute();
    }

    public override void PostExecute()
    {
        base.PostExecute();
    }


    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        var errorMsg = string.Empty;
        byte[] hashBytes;
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        try
        {
            string hashSource =
            (Row.ColA_IsNull ? "" : Row.ColA.ToString())
            + (Row.ColB_IsNull ? "" : Row.ColB.ToString())
            + (Row.ColC_IsNull ? "" : Row.ColC.ToString()));

            hashBytes = _md5.ComputeHash(
            System.Text.UnicodeEncoding.Unicode.GetBytes(hashSource));

            for (int i = 0; i <![CDATA[<]]> hashBytes.Length; i++)
            {
                sb.Append(hashBytes[i].ToString("X2"));
            }

            //Row.MD5 = "0x" + sb.ToString();
        }
        catch (Exception e)
        {
            errorMsg = e.Message;
        }
        finally
        {
            Row.MD5 = "0x" + sb.ToString();
        }

        if (errorMsg != null <![CDATA[&&]]> errorMsg != string.Empty)
            Row.MD5 = "Error";
    }
} 

</File>
</Files>



</ScriptComponentProject>
</ScriptComponentProject>
</ScriptComponentTransformation>-->
4

1 に答える 1

0

一見すると、hashSource の末尾に閉じ括弧が多すぎます。

それでも問題が解決しない場合は、SSIS パッケージから呼び出す DLL で同様のことを行います。たぶんこれが役立ちます:

        byte[] bs = System.Text.Encoding.ASCII.GetBytes(hashSource);
        bs = _md5.ComputeHash(bs);
        System.Text.StringBuilder s = new System.Text.StringBuilder();
        foreach (byte b in bs)
        {
            s.Append(b.ToString("x2").ToLower());
        }
        string md5hash = s.ToString();

.Net と SQL Server のハッシュを比較するときは、この狂気を念頭に置いてください。ハッシュ.aspx

于 2015-01-22T16:59:53.503 に答える