Call. Net assembly in SQL Server

Source: Internet
Author: User

It is a coincidence and helpless move to use this thing. Accidentally inserted some data after httputility. urlencodeunicode in the database. Some fields in the database are structured like % uxxxx.

Search for the half-day T-SQL urldecode function, found that the above Unicode is not supported. I am not familiar with T-SQL, time is also very urgent.

To call httputility. urldecode in a T-SQL, you need to contact the person who calls it. Check it, probablyCodeAs follows. If this item is used up, forget it. Remember it for future reference.

Create a DLL and a class. The Code is as follows.

 
Public Partial ClassSystemweb {[sqlmethod]Public StaticSqlstring urldecode (String Value){Return NewSqlstring (httputility. urldecode (Value));}}

Put it on the database server.

Then run the following T-SQL code

 

 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 = unsafeGo   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    

Then you can call this function in the T-SQL.

Select DBO. sqlurldecode (name) from table

For safety, when your ass is wiped out, remember to turn off the CLR.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.