• 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标记
    alter FUNCTION [dbo].[ReplaceHtmlTag]  
    (  
    @html AS NVARCHAR(max), 
    @length INT=500 
    )  
    RETURNS nvarchar(max) 
    AS  
    EXTERNAL NAME [SqlCLR].[NetSkycn.Data.SqlHelper].[ReplaceHtmlTag];  
    GO 
    

      

    /// <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

  • 相关阅读:
    linux---shell数组
    linux---shell传递参数
    Windows mysql免安装版配置。(版本号-5.6.45);
    contos 6.9 和 centos7 配置docker?
    数据库表的演化过程
    docker简单介绍。
    Linux 配置 mycat 和 分库分表配置。
    Linux 配置mysql 免安装版。
    mycat 简单介绍
    kibana 对es的简单操作。
  • 原文地址:https://www.cnblogs.com/xinzhyu/p/7338126.html
Copyright © 2020-2023  润新知