类似代码using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server;public partial class UserDefinedFunctions { [Microsoft.SqlServer.Server.SqlFunction] public static SqlString Function1(SqlString value) { // 在此处放置代码 return new SqlString("加密"+(value.IsNull?"": value.Value)); } };
打开vs2005/2008,新建项目,选择其它,然后选择数据库项目,接下来让你连接到sqlserver数据源,指定后,写clr的sql function就可以了。
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString Function1(SqlString value)
{
// 在此处放置代码
return new SqlString("加密"+(value.IsNull?"": value.Value));
}
};
谢谢了。
12楼的写出来明白多了,但问一下怎么在SQL语句中调用他们进行更新啊??
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString Function1(string str)
{
// 在此处放置代码
return str.ToUpper();
}
};
右击项目文件,点“生成”,这时编译 通过, 然后点“布署 ”,则会自动将些函数发布到指定的数据源。打开sqlserver management studio,连到.\sqlexpress,展开test库,可编程性》自定义存储过程,发现有了 function1测试select dbo.function1('aa')/*
AA
*/这仅仅是一个简单的例子。 你把函数体换成加密的步骤即可。
这都是c#的问题了,不用我多说了吧。
go
reconfigure;
go
exec sp_configure 'clr enabled', '1'
go
reconfigure;
exec sp_configure 'show advanced options', '1';
go
1,用t-sql写加密函数
2,写自定义函数用用sp_oa系列调用外部加密类com
3,用sp_addextendedproc注册扩展存储过程
4,走弯路,提供webservice进行加密,写自定义函数用sp_oa系列存储过程调用webservice进行加密码
5,其它方式
http://blog.csdn.net/jinjazz/archive/2007/12/09/1926086.aspx