Search code examples
.netazurevisual-studio-2013azure-blob-storageazure-storage-emulator

How to create a new CloudBlobContainer instance for my .NET MVC project (on Azure storage emulator )?


I have a sample .NET web-app project using an SQL db and an Azure blob for storage. I want to have several versions of the same project (copy, paste, and renanme the folder -> and then open in VS2013), but the problem is each project copy points to the same database and Azure blob. This has created problems when running new modified copies of the same project.

Searching the web, I found that entityframework code-first will create a new database for my project: simply go to the Web.config file -> connection string -> and renaming the 'Initial Catalog' property. The old .mfd file remains, but a new one is created following the new name given.

I am assuming that something similar is possible with Azure blob containers? How can I do this? I have tried to rename the CloudBlobContainer object instance (within the class code), but this only creates errors when running.

Also, why is the CloudBlobContainer object assigned a name in the code, say imagesBlobContainer, but when i look it up under VS2013 -> Server Explorer -> Azure -> Storage -> Development -> Blobs -> here it appears as 'images'? Shouldn't it not have the same name?


Solution

  • Just like your SQL DB connection string, connection string for storage account is picked from the config file. If you are doing development, you should see some setting value of which would be something like UseDevelopmentStorage=true. This tells the application to connect to storage emulator.

    Now coming on to your question about connecting to different storage accounts, a few things you need to understand:

    • There can be only one storage emulator on a machine or in other words there can be only one storage account installed on your computer.
    • If you want to have different versions of your application connect to different storage accounts, one thing you could do is have your application connect to a cloud storage account instead of development storage account. Then you could simply change the connection string in your config file and then your application would connect to that storage account.
    • Alternate solution would be to define the container name in your config file and change that for each version of your application. Then you would see different containers in your storage account.