Sql Server 调用dll文件

特此声明:在学习这项技能时,也看了不少博客,此博客只是自己的一个学习记录,应不涉及版权问题,不喜勿喷

最近做人工成本报表,由于薪资保密,数据库中工资数据都是加密的,将数据拿到程序中进行解密又太过繁琐,时间过长,因此想在数据库中直接解密,就需要在sql server中调动dll 来进行解密操作,由于解密需要调用平台其他类库并且有调用到system.web,最终没有成功解决,但是还是学会一项新技能,作此记录

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,sql,server,dll)