CLR SQL程序集:获取Bytestream?

OMG*_*ies 15 .net clr sqlclr visual-studio-2008

我有一个想要部署的SQL CLR DLL,但是发现你可以将字节流/ varbinary_literal/varbinary_expression/assembly位嵌入到文本文件中,以解决打包DLL并确保它可以访问CREATE ASSEMBLY的麻烦麻烦命令.

但我还没有找到如何获得字节流/ varbinary_literal/varbinary_expression /汇编位值.我没有找到任何一致的术语,以及我在使用中发现的内容Load().

救命?

San*_*ken 20

它只是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();
    }
Run Code Online (Sandbox Code Playgroud)

你应该像这样使用结果字符串:

string hexString = GetHexString(assemblyPath);
string sql = "CREATE ASSEMBLY [" + assemblyName + "] FROM " + hexString + 
             " WITH PERMISSION_SET = " + somePermissionSet;
Run Code Online (Sandbox Code Playgroud)

  • 谢谢 - 十六进制信息让我看到了这个代码:http://blog.waldenl.com/2009/12/command-line-hex-representation-of-file.html (2认同)

Fré*_*ric 7

这里找到varbinary,只有使用SQL Server Management Studio(SSMS)和本地SQL Server实例,才能生成没有用于生成它的自定义代码.

  1. createalter使用本地SQL Server上的本地路径在数据库中进行汇编.

    use yourBase
    go
    create assembly YourAssemblySqlName from N'YourLocalPath\YourAssemblyFile.dll'
    go
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在对象资源管理器中浏览到程序集.

    浏览到程序集

  3. 写下它的创作.

    编写程序集脚本

SSMS为您提供了varbinary.

  • 你也可以这样得:`SELECT af.content FROM sys.assemblies a INNER JOIN sys.assembly_files af ON a.assembly_id = af.assembly_id WHERE a.name = <@assemblyName>` (3认同)