SQL里执行CLR c#代码
这里只说一个重点:
1.直接在sql里执行clr代码的时候,sql还是会报错 说没有启用 clr
执行以下代码才会起作用
EXEC sp_configure 'clr enabled', 1; RECONFIGURE WITH OVERRIDE;
2.sql2008 只能识别.net 3.5的
3.c#里的string 对应 sql里的nvarchar
4.修改clr,如果修改不成功,则只能删除所有引用再重新创建
ALTER ASSEMBLY ComplexNumber
FROM 'C:\ComplexNumber.dll'
以下为举例说明,清除sql里的html标记
1 2 3 4 5 6 7 8 9 | alter FUNCTION [dbo].[ReplaceHtmlTag] ( @html AS NVARCHAR( max ), @length INT =500 ) RETURNS nvarchar( max ) AS EXTERNAL NAME [SqlCLR].[NetSkycn.Data.SqlHelper].[ReplaceHtmlTag]; GO |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /// <summary> /// 清除html标记 /// </summary> /// <param name="html"></param> /// <param name="length"></param> /// <returns></returns> [SqlFunction(IsDeterministic = true , DataAccess = DataAccessKind.None)] public static SqlString ReplaceHtmlTag( string html, int length = 0) { string strText = System.Text.RegularExpressions.Regex.Replace(html, "<[^>]+>" , "" ); strText = System.Text.RegularExpressions.Regex.Replace(strText, "&[^;]+;" , "" ); if (length > 0 && strText.Length > length) return strText.Substring(0, length); return (SqlString)strText; } |
参考链接:
http://zhoufoxcn.blog.51cto.com/792419/859245/
https://support.microsoft.com/en-us/help/2120850/error-message-after-you-restore-a-sql-server-2008-32-bit-dynamics-pos
--修改clr程序集
https://serverfault.com/questions/323014/how-to-update-a-clr-assembly-without-dropping-assembly-from-sql-server/323035
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
2011-08-10 web打印也能分页