none
Error in Connection String

    Question

  • Hi,

    I am creating a web app that includes forms as well.
    The application has a section where, a file has to be uploaded on Azure Storage blob. 
    I have specified the web config as <appSettings>
        <add key="webpages:Version" value="2.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="PreserveLoginUrl" value="true" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
        <add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=filesstore;AccountKey=l94+vPKdif2nc3TayAXE8UxvrfEAMHKZdKYeat3D44LEr5KHiJOrug9jDNDUU6Gx0TShzScDKxZpa5kPC3j7xw==" />
        <add key="StorageAccountKey" value ="l94+vPKdif2nc3TayAXE8UxvrfEAMHKZdKYeat3D44LEr5KHiJOrug9jDNDUU6Gx0TShzScDKxZpa5kPC3j7xw==" />
        <add key="StorageAccountName" value="filesstore" />

      </appSettings> 

     and 

    <add name="StorageConnectionString" connectionString="DefaultEndpointsProtocol=http;AccountName=filesstore;AccountKey=l94+vPKdif2nc3TayAXE8UxvrfEAMHKZdKYeat3D44LEr5KHiJOrug9jDNDUU6Gx0TShzScDKxZpa5kPC3j7xw=="  providerName="System.Data.SqlClient"/>

      and also I'm calling this inside the code as this 

                

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                    CloudConfigurationManager.GetSetting(StorageConnectionString));


                // Create the blob client.
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                // Retrieve reference to a previously created container.
                CloudBlobContainer container = blobClient.GetContainerReference("filesstore");

                // Retrieve reference to a blob named "myblob".
                CloudBlockBlob blockBlob = container.GetBlockBlobReference("filesstore");

                // Create or overwrite the "myblob" blob with contents from a local file.YourFileUpload.PostedFile.InputStream
                using (FileUploadControl.PostedFile.InputStream)
                {
                    blockBlob.UploadFromStream((FileStream)FileUploadControl.PostedFile.InputStream);
                }

    But I'm getting error as 

    in webapp An exception of type 'System.ArgumentNullException' occurred in Microsoft.WindowsAzure.Storage.dll but was not handled in user code.

    Kindly help me resolving this

    Tuesday, June 21, 2016 10:52 AM

All replies

  • If it's a WebApp maybe you should just try with ConfigurationManager.AppSettings["StorageConnectionString"]

    Even more important imho: I recommend that you NEVER paste (Storage account) credentials in a public forum. Now everybody can access your storage account, so I suggest you regenerate the keys asap.

    Tuesday, June 21, 2016 11:38 AM
  • Hi zehra1234,

    Your connection string contains this:

    providerName="System.Data.SqlClient"

    You can not access Azure Storage using the SQL provider. The correct format of the connection string is this:

    "DefaultEndpointsProtocol=https;AccountName=YOURACCOUNTNAME;AccountKey=YOURACCOUNTKEY"

    Robin


    Sr. Content Developer at Microsoft

    Thursday, June 30, 2016 7:45 PM