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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 南柯之石

软件工程师面试中应该出什么样的编程题 - 南柯之石 自引用泛型模式分析 一定间隔时间下重复执行一个函数的几个方法 为什么.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关掉。