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.
我有一个我想要部署的SQL CLR DLL,但是发现你可以将字节流/ varbinary_literal / varbinary_expression / assembly位嵌入到文本文件中,以解决打包DLL并确保它可以访问CREATE ASSEMBLY的麻烦麻烦命令。
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()
.
但我还没有找到如何获得字节流/ varbinary_literal / varbinary_expression / assembly位值。我没有找到任何一致的术语,以及我在使用Load()时发现的内容。
Help?
2 个解决方案
#1
18
It's just a hex representation of the dll. This bit should do the trick:
它只是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();
}
You should use the resulting string like so:
你应该像这样使用结果字符串:
string hexString = GetHexString(assemblyPath);
string sql = "CREATE ASSEMBLY [" + assemblyName + "] FROM " + hexString +
" WITH PERMISSION_SET = " + somePermissionSet;
#2
4
Found here, the varbinary
can be generated without custom code for generating it, only by using Sql Server Management Studio (SSMS) and a local SQL Server instance.
在这里找到varbinary,只需使用Sql Server Management Studio(SSMS)和本地SQL Server实例,就可以生成无需自定义代码的varbinary。
-
create
oralter
your assembly in your database using its local path on your local SQL Server.使用本地SQL Server上的本地路径在数据库中创建或更改程序集。
use yourBase go create assembly YourAssemblySqlName from N'YourLocalPath\YourAssemblyFile.dll' go
-
Browse to your assembly in Object Explorer.
在对象资源管理器中浏览到程序集。
-
Script its creation.
写下它的创作。
And SSMS give you the varbinary
.
SSMS为您提供varbinary。
#1
18
It's just a hex representation of the dll. This bit should do the trick:
它只是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();
}
You should use the resulting string like so:
你应该像这样使用结果字符串:
string hexString = GetHexString(assemblyPath);
string sql = "CREATE ASSEMBLY [" + assemblyName + "] FROM " + hexString +
" WITH PERMISSION_SET = " + somePermissionSet;
#2
4
Found here, the varbinary
can be generated without custom code for generating it, only by using Sql Server Management Studio (SSMS) and a local SQL Server instance.
在这里找到varbinary,只需使用Sql Server Management Studio(SSMS)和本地SQL Server实例,就可以生成无需自定义代码的varbinary。
-
create
oralter
your assembly in your database using its local path on your local SQL Server.使用本地SQL Server上的本地路径在数据库中创建或更改程序集。
use yourBase go create assembly YourAssemblySqlName from N'YourLocalPath\YourAssemblyFile.dll' go
-
Browse to your assembly in Object Explorer.
在对象资源管理器中浏览到程序集。
-
Script its creation.
写下它的创作。
And SSMS give you the varbinary
.
SSMS为您提供varbinary。