Reputation: 103388
Is there a way I can do .NET's Server.UrlEncode()
function using SQL Server 2008?
I'm looking for a way of formatting text a user has submitted for File Name purposes using the @Name
the user has provided rather than having to convert application end, then send both @Name
and @FileName
.
I hope this makes sense cheers
Upvotes: 3
Views: 4847
Reputation: 74550
You are looking to perform Percent-Encoding/Decoding which is defined in Section 2.1 of RFC 3986, titled "Uniform Resource Identifier (URI): Generic Syntax".
You can use this section to determine how to percent-encode/decode URIs in T-SQL.
Specifically, you'll want to pay attention to all of Section 2: Characters with specific attention paid to Section 2.4: When to Encode or Decode.
The best way to do this, of course, is to perform this before/after you save/query the database. Relational databases in general aren't made for this kind of computational work.
If you use code, you might want to take a look at the Microsoft Web Protection Library on CodePlex, as it contains mechanisms for percent-encoding/decoding which are much more up-to-date in regards to taking into account vulnerabilities that can arise from poor encoding schemes.
Upvotes: 0