The procedure is as follows:
1. Create a project:
2. The following prompt is displayed: click OK.
3. The database to be deployed appears.
4. Select Yes
5. Write the following code:
Public partial class userdefinedfunctions {[Microsoft. sqlserver. server. sqlfunction] public static sqlstring md5function (string source) {// place the code return md5string (source) here );} /// <summary> /// use MD5 encryption /// </Summary> /// <Param name = "Source"> string to be encrypted </param> // /<returns> return encrypted ciphertext </returns> Public static string md5string (string source) {try {byte [] DATA = system. text. encoding. getencoding (1, 1252 ). getbytes (source); Data = new md5cryptoserviceprovider (). computehash (data); string returnvalue = ""; for (INT I = 0; I <data. length; I ++)/* tostring ("X2") is the string format control character in C #. X is hexadecimal. 2 indicates that each time it is two digits, for example, 0x0a. If there is no 2, only 0 XA is output. Assume that there are two numbers: 10 and 26. Normally, 0xa and 0 x 1A are displayed in hexadecimal notation. This will make it look untidy. To look good, you can specify "X2 ", the result is: 0x0a, 0x1a */returnvalue + = data [I]. tostring ("X2"); Return returnvalue;} catch (systemexception ex) {Throw ex ;}}};
6. Compile and deploy the framework (note: the framework must be reduced to 3.5 to be deployed successfully)
7. The database executes the following statements:
exec sp_configure 'show advanced options', '1';goRECONFIGURE;goexec sp_configure 'clr enabled', '1'goRECONFIGURE;exec sp_configure 'show advanced options', '1';goRECONFIGURE;
8. Execute the newly created function: