更新时间:2023-09-22 20:07:10
创建T-SQL格式的字符串,例如:
Create a T-SQL format string, something like:
CREATE ASSEMBLY {0}
AUTHORIZATION dbo
FROM 0x{1}
WITH PERMISSION_SET = SAFE
GO
然后,为该字符串提供Database.ExecuteNonQuery
调用的参数,例如
Then, supply this string with arguments to a Database.ExecuteNonQuery
call, e.g.
database.ExecuteNonQuery(string.Format(
installClrAssemblyFormatString,
clrAssemblyName,
hexFormattedClrAssemblyContents));
为了简化部署,我将CLR程序集作为数据库管理实用程序的嵌入式资源(负责创建数据库,脚本表,设置权限等)包含在内.
将CLR程序集加载到数据库后,您仍然需要对各种存储的proc进行"CREATE PROCEDURE"调用.我似乎还记得从SSMS抓取到该T-SQL,但是用手工编写它们并不是很难.
To make deployment easier, I included the CLR assemblies as embedded resources of my database management utility (the one responsible for creating the dataase, scripting tables, setting up permissions, etc).
Once the CLR assemblies have been loaded to the database, you still need to have "CREATE PROCEDURE" calls for the various stored procs. I seem to remember snagging this T-SQL from SSMS, but they''re not terribly difficult to code by hand.