可以从Azure Blob Storage下载文件



我有一个SSIS包如何连接到Azure并恢复json文件作为配置文件。直到有一天,没有任何解释,我开始出现一个错误。

请注意连接成功,并且我的IP地址已被列入白名单。

代码
115  StorageCredentials credentials = new StorageCredentials(accountName, accountKey);
116  CloudStorageAccount storage = new CloudStorageAccount(credentials, true);
117  CloudBlobClient client = storage.CreateCloudBlobClient();
118  CloudBlobContainer blobContainer = client.GetContainerReference(configFileContainer);
119  CloudBlockBlob blob = blobContainer.GetBlockBlobReference(configFileName);
120
121  string configJson = blob.DownloadText();  // ERROR

误差

Client and server cannot communicate because they do not have any algorithms in common.

堆栈跟踪
Error: 0x1 at ST - Load Config: An error occurred while sending the request.   at Microsoft.Azure.Storage.Core.Executor.Executor.<ExecuteAsync>d__1`1.MoveNext()
--- End of stack trace from previous location where the exception was raised ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Storage.Core.Executor.Executor.<>c__DisplayClass0_0`1.<ExecuteSync>b__0()
at Microsoft.Azure.Storage.Core.Util.CommonUtility.RunWithoutSynchronizationContext[T](Func`1 actionToRun)
at Microsoft.Azure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)
at Microsoft.Azure.Storage.Blob.CloudBlob.DownloadRangeToStream(Stream target, Nullable`1 offset, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
at Microsoft.Azure.Storage.Blob.CloudBlob.DownloadToStream(Stream target, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
at Microsoft.Azure.Storage.Blob.CloudBlockBlob.DownloadText(Encoding encoding, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
at ST_9b0ac6493260451aa379f7276b92d98e.ScriptMain.Main() dans ...344f55fca5c54a4f832c7376bc4a2b16ScriptMain.cs:ligne 121
Error: 0x6 at ST - Load Config: The script returned an error result.
Task failed: ST - Load Config

问题是使用的连接协议过时了。Azure支持TLS1.2协议

解决问题的两种方法:

  • 在您的机器上=>启用TLS协议并禁用旧版本。
  • 代码中=>禁用过时的协议,并在连接到Azure之前添加此代码来强制使用TLS1.2。

就像这样:

108  // Remove insecure protocols (SSL3, TLS 1.0, TLS 1.1)
109  ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
110  ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls;
111  ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls11;
112  // Add TLS 1.2
113  ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
114
115  StorageCredentials credentials = new StorageCredentials(accountName, accountKey);
116  CloudStorageAccount storage = new CloudStorageAccount(credentials, true);
117  CloudBlobClient client = storage.CreateCloudBlobClient();
118  CloudBlobContainer blobContainer = client.GetContainerReference(configFileContainer);
119  CloudBlockBlob blob = blobContainer.GetBlockBlobReference(configFileName);

最新更新