CLR SQL 程序集:获取字节流? [英] CLR SQL Assembly: Get the Bytestream?
问题描述
我有一个想要部署的 SQL CLR dll,但我发现您可以将字节流/varbinary_literal/varbinary_expression/assembly 位嵌入到文本文件中,以避开打包 DLL 并确保其可访问的麻烦创建汇编命令.
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_expression/assembly bits 值.我没有找到任何一致的术语,以及我在使用 Load()
时不断发现的内容.
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 的十六进制表示.这一点应该可以解决问题:
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;
这篇关于CLR SQL 程序集:获取字节流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!