CLR SQL大会:获取字节流?字节、大会、CLR、SQL

由网友(她是场海啸、)分享简介:我有一个SQL CLR DLL我要部署,而是发现你可以嵌入字节流/ varbinary_literal / varbinary_ex pression /组装位到一个文本文件来解决包装一个DLL,使凌乱麻烦确保它是可访问的 CREATE ASSEMBLY命令。I have a SQL CLR dll I want t...

我有一个SQL CLR DLL我要部署,而是发现你可以嵌入字节流/ varbinary_literal / varbinary_ex pression /组装位到一个文本文件来解决包装一个DLL,使凌乱麻烦确保它是可访问的 CREATE ASSEMBLY命令。

I have a SQL CLR dll I want to deploy, but have found you can embed the byte stream/varbinary_literal/ varbinary_expression/assembly bits into a text file to get around the messy hassle of packaging a DLL and making sure it's accessible for the CREATE ASSEMBLY command.

但我还没有找到是如何得到的字节流/ varbinary_literal / varbinary_ex pression /装配位值。我还没有发现任何一致的术语,什么我一直在寻找使用加载()

But what I have yet to find is how to get that byte stream/varbinary_literal/ varbinary_expression/assembly bits value. I haven't found any consistent terminology, and what I keep finding in using Load().

帮助?

推荐答案

这是该DLL的只是一个十六进制再presentation。该位应该做的伎俩:

It's just a hex representation of the dll. This bit should do the trick:

    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();
    }

您应该使用生成的字符串,像这样:

You should use the resulting string like so:

string hexString = GetHexString(assemblyPath);
string sql = "CREATE ASSEMBLY [" + assemblyName + "] FROM " + hexString + 
             " WITH PERMISSION_SET = " + somePermissionSet;
阅读全文

相关推荐

最新文章