我有一个我想部署的SQL CLR DLL,但是发现你可以将字节流/ varbinary_literal / varbinary_expression / assembly位嵌入到文本文件中,以解决打包DLL并确保CREATE ASSEMBLY command可以访问的麻烦。
但我还没有找到如何获得字节流/ varbinary_literal / varbinary_expression /汇编位值。我没有找到任何一致的术语,以及我在使用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;
找到here,只有使用SQL Server Management Studio(SSMS)和本地SQL Server实例,才能生成varbinary
而无需生成它的自定义代码。
create
或alter
使用本地SQL Server上的本地路径在数据库中进行汇编。
use yourBase
go
create assembly YourAssemblySqlName from N'YourLocalPath\YourAssemblyFile.dll'
go
SSMS为您提供varbinary
。