惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
The GitHub Blog
The GitHub Blog
博客园_首页
T
The Blog of Author Tim Ferriss
H
Hackread – Cybersecurity News, Data Breaches, AI and More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
I
InfoQ
量子位
J
Java Code Geeks
P
Proofpoint News Feed
有赞技术团队
有赞技术团队
Webroot Blog
Webroot Blog
Martin Fowler
Martin Fowler
D
Docker
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
V
Vulnerabilities – Threatpost
罗磊的独立博客
P
Proofpoint News Feed
T
The Exploit Database - CXSecurity.com
Cyberwarzone
Cyberwarzone
P
Privacy & Cybersecurity Law Blog
Last Week in AI
Last Week in AI
爱范儿
爱范儿
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
V
V2EX
Simon Willison's Weblog
Simon Willison's Weblog
AI
AI
Y
Y Combinator Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
GbyAI
GbyAI
V
Visual Studio Blog
H
Heimdal Security Blog
S
Secure Thoughts
B
Blog RSS Feed
雷峰网
雷峰网
T
Tenable Blog
C
Check Point Blog
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
About on SuperTechFans
Recent Commits to openclaw:main
Recent Commits to openclaw:main

博客园 - 南柯之石

用户中心 - 博客园 自引用泛型模式分析 一定间隔时间下重复执行一个函数的几个方法 为什么.NET Framework就没有个专门的P/Invoke Library? Which would you perfer? "easy and fast and works well" or "hard and time consuming and error prone" 在ListView的GroupItem头中显示每列的Summary 小例子背后的大道理——用户需求+设计原则+正确应用 =设计方案 GET和POST有什么区别?及为什么网上的多数答案都是错的。 小例子背后的大道理——Adapter模式详解 小例子背后的大道理——从DIP中“倒置”的含义说接口的正确使用 XmlSerializer, DataContractSerializer 和 BinaryFormatter区别与用法分析 使用WPF开发的扫雷游戏,双系统主题复刻版 技术误用带来的技术偏见及所谓的“经验” 从一个UI交互设计师的讲座说开去 NoSQL和MemeryCache的出现意味着传统数据库使用方式的变革吗? 不使用反射进行C#属性的运行时动态访问 一次模块划分的争论及其结局 电子书籍质量保证事件分析 T-SQL 操作XML示例
在SQL Server中调用.NET程序集
南柯之石 · 2011-12-20 · via 博客园 - 南柯之石

使用到这东西完全是个巧合和无奈之举。不小心在数据库中插入了一些HttpUtility.UrlEncodeUnicode之后的数据。数据库里的一些字段成了%uxxxx%uxxxx这样的结构。

搜索了半天T-SQL UrlDecode的函数,发现都不支持上面这种Unicode的。自己对T-SQL又不熟悉,时间也很紧迫。

解铃还须系铃人,想到在T-SQL里调用HttpUtility.UrlDecode应该会比较方便。查了一下,大概代码如下。这东西用完就忘,记下来备查吧。

建立一个DLL,一个类,代码如下。

public partial class SystemWeb 
    { 
        [SqlMethod] 
        public static SqlString UrlDecode(string value) 
        { 
            return new SqlString(HttpUtility.UrlDecode(value)); 
        } 
    }

放到数据库服务器上。

之后运行下面的T-SQL代码

EXEC sp_configure 'show advanced options','1'; 
GO 
RECONFIGURE; 
GO 
EXEC sp_configure 'clr enabled','1' 
RECONFIGURE; 
GO 

ALTER DATABASE DBName SET TRUSTWORTHY ON 
GO 

CREATE ASSEMBLY 
[System.Web] FROM 
'C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\System.Web.dll' 
WITH permission_set = UNSAFE 
GO 

CREATE ASSEMBLY SQL_CLR_Url 
FROM 'D:\SqlClr.dll' 
WITH PERMISSION_SET = UNSAFE 

GO

CREATE FUNCTION SqlUrlDecode(@urlstr NVARCHAR(4000)) 
RETURNS NVARCHAR(4000) 
AS 
EXTERNAL NAME SQL_CLR_Url.[SqlClr.SystemWeb].UrlDecode 
GO   

然后就可以在T-SQL里调用这个函数了。

select dbo.SqlUrlDecode(Name) from Table

安全起见,屁股擦完了,记得把clr关掉。