Wednesday, October 17, 2012

Setup and configure a MVC4 project for Cloud Service(web role) and SQL Azure



 

I aim at keeping this blog post updated and add related posts to it. Since there are a lot of these out there I link to others that has done kind of the same before me, kind of a blog-DRY pattern that I'm aiming for. I also keep all mistakes and misconceptions for others to see. As an example; if I hit a stacktrace I will google it if I don't directly figure out the reason for it. I will then probably take the most plausible result and try it out. If it fails because I misinterpreted the error I will not delete it from the log but keep it for future reference and for others to see. That way people that finds this blog can see multiple solutions for indexed stacktraces and I can better remember how to do stuff. To avoid my errors I recommend you to read through it all before going from start to finish.
The steps:
  1. Setup project in VS2012. (msdn blog)
  2. Setup Azure Services (half of mpspartners.com blog)
  3. Setup connections strings and configuration files (msdn blog + notes)
  4. Export certificates.
  5. Create Azure package from vs2012 and deploy to staging (same steps as for production).
  6. Connections string error

 

  1. Set up the visual studio project:
http://blogs.msdn.com/b/avkashchauhan/archive/2011/11/08/developing-asp-net-mvc4-based-windows-azure-web-role.aspx


 

  1. Then login in to Azure to setup the services:
Stop following this guide at the "publish website" part since we'll be uploading a package.
http://www.mpspartners.com/2012/09/ConfiguringandDeployinganMVC4applicationasaCloudServicewithAzureSQLandStorage/


 

  1. When set up (connection strings for debug and release and all), follow this guide to set up the configuration files:
http://msdn.microsoft.com/en-us/library/windowsazure/hh369931.aspx

Trying to package our application at this step will generate the following warning:
3>MvcWebRole1(0,0): warning WAT170: The configuration setting 'Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString' is set up to use the local storage emulator for role 'MvcWebRole1' in configuration file 'ServiceConfiguration.Cloud.cscfg'. To access Windows Azure storage services, you must provide a valid Windows Azure storage connection string.


 

Right click the web role under roles in solution manager and choose properties. Choose "Service configuration: Cloud". At "specify storage account credentials" we will copy/paste our account name and key from the Azure management platform.
3.1

4. Right click Remote desktop Configuration and select certificate and export to file. We need to allow it in Portal manager.

4.1

5 Now right click the cloud project and select package.

5.1 Showing dialogue box.



 

5.2 Package success



 

Now copy the path to the packaged file and go to management portal again.
Click your web role and choose staging (or production). Upload.
5.3


Tick the box about the single instance if that's what you want or you don't know what it means. Otherwise the following will happen (see image 4.6)
5.4 Dialogue box



 

When you have clicked the symbol for accept- button you will see the following screen with some green indicators down at the right corner. Click them if you want to see status.
5.5 Information screen.


5.6
"Failed to deploy application.
The upload application has at least one role with only one instance. We recommend that you deploy at least two instances per role to ensure high availability in case one of the instances becomes unavailable. "
To fix, go to step 5.4



If you forgot to (or just didn't know you were supposed to) export your certificates. The following error will occur.
Side note, the following thread suggests. To prevent: "Enable Remote Desktop for all roles" when right-clicking BIAB and choosing "Package". But in my case it was the not so present certificates. I fund the solution here.
http://social.msdn.microsoft.com/Forums/en-US/dotnetstocktradersampleapplication/thread/0e94c2b5-463f-4209-86b9-fc257e0678cd
5.7



5.8 Success!


5.9 Nice URL n' all. (More on that at another blog post).

6. If you try to login and get



When this error occurs many web sites suggest this is because you need: http://nuget.org/packages/Microsoft.AspNet.Providers.LocalDB

Or : http://nuget.org/packages/Microsoft.AspNet.Providers

But it can also be that you don't have the correct setup for converting connectionstrings between your web.config to your debug.web.config(or release.web.config, whichever your using).
Run as suggested in the "ordinary project in your solution.

 



Go to the management portal and click update.

 


 


 


 


 


 


 


 

No comments:

Post a Comment