Created
August 8, 2013 21:54
-
-
Save caseywatson/6189129 to your computer and use it in GitHub Desktop.
This SQL CLR UDF will download data given a URL and return a VarBinary. Helpful in cases where you are moving binary objects from the database to some other location (in my case, Azure) with minimal impact.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Data; | |
| using System.Data.SqlClient; | |
| using System.Data.SqlTypes; | |
| using Microsoft.SqlServer.Server; | |
| using System.Net; | |
| public partial class UserDefinedFunctions | |
| { | |
| [Microsoft.SqlServer.Server.SqlFunction] | |
| public static SqlBytes Download(SqlString sqlUrl) | |
| { | |
| var url = sqlUrl.ToString(); | |
| if (String.IsNullOrEmpty(url)) | |
| return null; | |
| using (var webClient = new WebClient()) | |
| { | |
| return new SqlBytes(webClient.DownloadData(url)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment