XLSExport: A CLR procedure to export proc results to Excel
A CLR procedure utilizing the NPOI library to export the results of a passed stored procedure to an Excel spreadsheet.
2011-06-23
10,635 reads
CREATE ASSEMBLY [Hashbytes] FROM D:\HashBytes.dll --Location of precompiled DLL WITH PERMISSION_SET = UNSAFE; CREATE FUNCTION Hashbyte(@Inputstring NVARCHAR(MAX)) RETURNS NVARCHAR(MAX) WITH EXECUTE AS CALLER AS EXTERNAL NAME Hashbytes.hashbytes.hasBytes C# Code --------- using System; using System.Collections; using System.Data; using System.Security.Cryptography; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; public class hashbytes { public hashbytes() { } public static string hashBytes(SqlString Hashsource) { string str = Convert.ToString(Hashsource); SHA256 sha = new SHA256CryptoServiceProvider(); // used to create the SHA256 hash byte[] hashBytes = sha.ComputeHash(System.Text.UnicodeEncoding.Unicode.GetBytes(str)); System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < hashBytes.Length; i++) { sb.Append(hashBytes[i].ToString("X2")); } return "0X" +sb.ToString(); } }