.net - CLR SQL 程序集 : Get the Bytestream?

标签 .net visual-studio-2008 clr sqlclr

我有一个想要部署的 SQL CLR dll,但我发现您可以将字节流/varbinary_literal/varbinary_expression/assembly 位嵌入到文本文件中,以避开打包 DLL 并确保 CREATE ASSEMBLY command 可访问的麻烦。

但是我还没有找到如何获得该字节流/varbinary_literal/varbinary_expression/assembly bits 值。我没有找到任何一致的术语,以及我在使用 Load() 时不断发现的。

最佳答案

它只是 dll 的十六进制表示。这一点应该可以解决问题:

    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;

关于.net - CLR SQL 程序集 : Get the Bytestream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2885335/

相关文章:

c# - WeakEventDelegate 实现 - 反馈请求

.net - ScrollViewer 的性能问题

VSTS : Different checksum values given for '*.g.cs' Files 的 WPF 警告

.net - Visual Studio 项目构建为可执行文件和 DLL

c# - JVM 和 CLR 如何知道何时启动

.net - 各种 CLR 运行时有多大?

.net - 如何确定要在我的 svcutil 命令行中包含哪些架构文件 (xsd)?

c# - SimpleInjector - 注册对象依赖于另一个注册对象的值

.net - 无法调试 Windows 服务 - 当前不会命中断点

visual-studio-2010 - 从 Visual Studio 2008 转换的解决方案在 Visual Studio 2010 中的 Gacutil 后期构建步骤失败