ストレージアカウントにコンテナのリストを取得したり、データベースから保存された資格情報を使用してSQL Serverから直接コンテナ内のBLOBのリストを取得できますか?
David Makogon氏によると、SQL Serverのコンテナ/ BLOBをリストする場合は、SQL CLRストアドプロシージャを使用できます。そして、私はコンテナからブロブをリストするための実例を持っています。それを参照することができます。
SQL CLRのStoredProcedure
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void SqlStoredProcedure1()
{
// Put your code here
string StorageAccount = "myaccount";
string StorageKey = "accountkey";
string containername = "mycontainer";
string requestMethod = "GET";
string mxdate = "";
string storageServiceVersion = "2014-02-14";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(string.Format(CultureInfo.InvariantCulture,
"https://{0}.blob.core.windows.net/{1}?restype=container&comp=list",
StorageAccount,
containername
));
req.Method = requestMethod;
//specify request header
mxdate = DateTime.UtcNow.ToString("R");
string canonicalizedHeaders = string.Format(
"x-ms-date:{0}\nx-ms-version:{1}",
mxdate,
storageServiceVersion);
string canonicalizedResource = string.Format("/{0}/{1}\ncomp:list\nrestype:container", StorageAccount, containername);
string stringToSign = string.Format(
"{0}\n\n\n\n\n\n\n\n\n\n\n\n{1}\n{2}",
requestMethod,
canonicalizedHeaders,
canonicalizedResource);
HMACSHA256 hmac = new HMACSHA256(Convert.FromBase64String(StorageKey));
string signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign)));
String authorization = String.Format("{0} {1}:{2}",
"SharedKey",
StorageAccount,
signature
);
string AuthorizationHeader = authorization;
req.Headers.Add("Authorization", AuthorizationHeader);
req.Headers.Add("x-ms-date", mxdate);
req.Headers.Add("x-ms-version", storageServiceVersion);
DataTable dt = new DataTable();
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
{
var stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();
StringReader theReader = new StringReader(content);
DataSet theDataSet = new DataSet();
theDataSet.ReadXml(theReader);
dt = theDataSet.Tables[2];
}
string blobs = "";
foreach (DataRow item in dt.Rows)
{
blobs += item[0].ToString() + ";";
}
SqlContext.Pipe.Send(blobs);
}
}
共通言語ランタイム(CLR)統合機能は、Microsoft SQL Serverのデフォルトではオフで、SQL Serverプロジェクトのアイテムを使用するために有効にする必要があります。 enable CLR integrationには、sp_configureストアド・プロシージャのclr enabledオプションを使用します。
そして、SQL CLRストアドプロシージャの使用方法を知りたい場合は、this tutorialを参照してください。
実際にAzure Storage API呼び出しをSQL ServerからAzureストレージにしたいですか? REST呼び出しを行う必要があるので、これを達成するにはCLRプロシージャが必要です(しかし、これは主要な "コードの匂い"です)。 –