Question

I have an MVC4 project that I am running using Azure websites preview.

My problem is that I cant upload a blob into my blob storage container when I have deployed my website to azure, however the upload works fine when I'm debugging locally.

This is the exception and stack trace I get when deployed and I try to upload to a container:

No valid combination of account information found. at Microsoft.WindowsAzure.Storage.CloudStorageAccount.b__0(String err) at Microsoft.WindowsAzure.Storage.CloudStorageAccount.TryParse(String s, CloudStorageAccount& accountInformation, Action`1 error) at Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(String connectionString) at MyProj.Controllers.ImageController.Upload(ImageViewModel model)

Specifically as per the stack trace it is the .Parse method which is failing.

The code I am using to connect to the blob storage is straight from the azure how-to documentation:

string connectionString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

Once again, this works fine when I running locally on my dev box, I can upload successfully with no problems. However it gives me this error when deployed and I attempt to do exactly the same thing.

I'm guessing my storageConnectionString is being messed with during the web deploy publish process but I'm unsure about how to resolve this?

Was it helpful?

Solution 3

Store your storage connection string in AppSettings, not in ConnectionStrings section. And, pasting here the actual connection string will help us help you (you may put * for the account key).

OTHER TIPS

Be sure that

1) You are using the proper protocol for diagnostics (double click the role -> configuration tab -> select the configuration -> under "Diagnostics", click the ellipsis -> try to click OK...if it gives error that you must use https, change the connection strings to https)

and

2) No white spaces allowed...i.e. UseDevelopmentStorage=true;DevelopmentStorageProxyUri=https://127.0.0.1 instead of UseDevelopmentStorage=true; DevelopmentStorageProxyUri=https://127.0.0.1

(note space after the semi-colon)

Check for https and white space in all connection strings on the Settings tab

---EDIT----

Putting "https" in actually screwed everything up for us. Worker role would throw an exception ("Handshack failed due to an unexpected packet format.") and then cycle between unknown and destroyed. Removed the "s" in "https" and made sure there were no white spaces and voila.

Another way of getting the CloadStorageAccount instance is doing this

StorageCredentials credentials = new StorageCredentials(accountName, accountKey);
CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);

This should help anyone that has this parsing problem.

I think, that could not be the cause of the problem as was expressed by Sandino Di Mattia. I had the same one when upgraded the SDK to the 2.0 and turned out that the API's connection string parser tolerates no more whitespaces in the connection string and it was not mentioned anywhere. If this kind of change was intentional, I would call it a nasty move...

I got this error because missed the prefix BlobEndpoint= before Blob SAS URL:

wrong appsettings.json

{
  "TestBlobWriter": {
    "ConnectionString": "https://test.blob.core.windows.net/test-container?sp=*&st=*&se=*&spr=*&sv=*&sr=*&sig=*",
    "ContainerName": "test-container"
  }
}

correct appsettings.json

{
  "TestBlobWriter": {
    "ConnectionString": "BlobEndpoint=https://test.blob.core.windows.net/test-container?sp=*&st=*&se=*&spr=*&sv=*&sr=*&sig=*",
    "ContainerName": "test-container"
  }
}

Be aware, too, that casing in the connection string matters. I experienced this error before when a large merge caused someone to "AccountName" to "Accountname" in my Web.config. Using the correct casing fixed the error.

If you are very sure that, the connection string copied from Azure service is same as you pasted, then please check whether you have given any carriage return / space for the sake of readability, it's also one of the reasons caused that issue which you have experienced. I tried to give +1 for @scottndecker but couldn't since I don't have 15 reputation.

Don't forget to include the "https://" or "https://" when using the proxyUri. Like:

UseDevelopmentStorage=true;DevelopmentStorageProxyUri=https://127.0.0.1

I got this because I had accidently added a newline character (\r\n) at the end of the string.

I was facing same issue. You need to use Microsoft.WindowsAzure.Storage name space and make sure there is not an extra space in connection string.

I got this error because I used the wrong nuget package, (I am using dot net 4.6.1)

The wrong package was: WindowsAzureStorage.Helper

The correct package is: WindowsAzure.Storage

and make sure you use the namespace: using Microsoft.WindowsAzure.Storage;

I encountered this error when I had migrated a storage connection string from app settings literal to a keyvault reference using @Microsoft.KeyVault(SecretUri=https...) I'd created a new function app and had forgotten to turn on system-assigned identity and given the app access to keyvault. Hence, the symptom was an undefined app settings value - a failed storage connection attempt.

I will share the solution of my problem. I was thinking that the brackets must stay and enter the information inside them. After removing the brackets, my problem was solved.

From:

string eventHubName = "{Event Hub name}";

To:

string eventHubName = "Event Hub name";

The same goes for: eventHubConnectionString, storageAccountName and storageAccountKey

To solve this issue on azure, don't use the default string but use a minimalistic version such as :

<add name="StorageConnection" 
    connectionString="DefaultEndpointsProtocol=https;AccountName=name;AccountKey=yourkey;EndpointSuffix=core.windows.net" />

Without whitespace or line breaks!!

The error message doesn't say anything about the account key being wrong, but that was the problem in my case.

I was developing a new application and copied/pasted the key from our team's config file. I started getting this error in the new application, but the only one worked just fine. It turns out that somewhere in our config file, a + was replaced by \u002B. After coping/pasting the correct key, the new app worked just fine.

I also got the same issue, and i found it in the namespace. The CloudStorageAccount class is present in both the namespaces

using Microsoft.WindowsAzure;

using Microsoft.WindowsAzure.Storage;

So I just removed WindowsAzure namespace and added WindowsAzure.Storage in my code.

Previous Code:

using Microsoft.WindowsAzure;

Fixed Code:

using Microsoft.WindowsAzure.Storage;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top