16

デプロイしたいSQLCLRdllがありますが、バイトストリーム/ varbinary_literal / varbinary_expression / assemblyビットをテキストファイルに埋め込んで、DLLをパッケージ化し、CREATEASSEMBLYでアクセスできるようにするという面倒な作業を回避できることがわかりました。コマンド

しかし、私がまだ見つけていないのは、そのバイトストリーム/ varbinary_literal /varbinary_expression/アセンブリビット値を取得する方法です。一貫性のある用語は見つかりませんでした。また、を使用して見つけ続けているものもありませんLoad()

4

2 に答える 2

23

これは、dllの16進表現にすぎません。このビットはトリックを行う必要があります:

    static string GetHexString(string assemblyPath)
    {
        if (!Path.IsPathRooted(assemblyPath))
            assemblyPath = Path.Combine(Environment.CurrentDirectory, assemblyPath);

        StringBuilder builder = new StringBuilder();
        builder.Append("0x");

        using (FileStream stream = new FileStream(assemblyPath,
              FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            int currentByte = stream.ReadByte();
            while (currentByte > -1)
            {
                builder.Append(currentByte.ToString("X2", CultureInfo.InvariantCulture));
                currentByte = stream.ReadByte();
            }
        }

        return builder.ToString();
    }

結果の文字列は次のように使用する必要があります。

string hexString = GetHexString(assemblyPath);
string sql = "CREATE ASSEMBLY [" + assemblyName + "] FROM " + hexString + 
             " WITH PERMISSION_SET = " + somePermissionSet;
于 2010-05-21T22:29:16.227 に答える
7

ここにある、は、 SQL Server Management Studio( SSMS varbinary)とローカルSQL Serverインスタンスを使用することによってのみ、生成するためのカスタムコードなしで生成できます。

  1. createまたはalter、ローカルSQLServerのローカルパスを使用するデータベース内のアセンブリ。

    use yourBase
    go
    create assembly YourAssemblySqlName from N'YourLocalPath\YourAssemblyFile.dll'
    go
    
  2. オブジェクトエクスプローラーでアセンブリを参照します。

    アセンブリへのブラウジング

  3. その作成をスクリプト化します。

    アセンブリのスクリプト

そして、SSMSはあなたにを与えますvarbinary

于 2016-04-01T18:03:30.273 に答える