• Sql Server 数据库中调用dll文件


    1.首先新建一个空的解决方案,并添加一个类库,代码如下,编译并生产dll
    
    using System;  
    using System.Collections.Generic;  
    using System.Data.SqlTypes;  
    using System.Linq;  
    using System.Text;  
      
    namespace TEST  
    {  
        public class TestTrans  
        {  
            [Microsoft.SqlServer.Server.SqlFunction]  
            public static SqlString GenerateDecryptString(string name)  
            {  
                string decode = string.Empty;  
                decode = string.Format("HELLO WORLD  {0}!", name);//DecryptString(dataXML.Value);  
                SqlString sqlValue = new SqlString(decode);  
                return sqlValue;  
            }  
        }  
    }  
    
    
    2.启用CLR功能
    默认情况下,SQL Server中的CLR是关闭的,所以我们需要执行如下命令打开CLR:
      exec sp_configure 'clr enabled',1   
      reconfigure   
      Go
    
    
    3.将程序集引用到数据库中
    CREATE ASSEMBLY testHelloWorld FROM 'C:TEST.dll'      --('C:/TEST.dll'w为错误写法)
    
    
    4.创建函数
    
    CREATE FUNCTION dbo.clrHelloWorld     
    (     
        @name as nvarchar(200)     
    )      
    RETURNS nvarchar(200)    
     AS EXTERNAL NAME testHelloWorld.[TEST.TestTrans].GenerateDecryptString   
    
    
    5.调用函数
     
    SELECT dbo.clrHelloWorld('耿耿')  
    
    6.执行结果
    
    HELLO WORLD  耿耿!



  • 相关阅读:
    bzoj 1858 线段树
    bzoj 1877 最小费用流
    bzoj 1833 数位dp
    Codeforces Round #285 (Div. 1) B
    HDU2028 Lowest Common Multiple Plus
    HDU5706 GirlCat
    HDU2022 海选女主角
    687E: TOF
    687D: Dividing Kingdom II
    687D: Dividing Kingdom II
  • 原文地址:https://www.cnblogs.com/smartsmile/p/6234035.html
Copyright © 2020-2023  润新知