nopCommerce 2.40 in the cloud via Windows Azure

Recently I modified open source e-commerce and shopping cart solution, nopCommerce, to work in the cloud.  First, I have to thank Aleš Rosina at shelastyle.net because his blog post got me started and I’m essentially just expanding on his work.  If you haven’t worked with or used nopCommerce I have to say it is a very impressive .NET-based shopping solution that handles inventory, shipping, payments, and many more features.

Jumping right into the meat of this post I started with the most current version of nopCommerce 2.40.  Here are the steps I followed to get nopCommerce running on Windows Azure.

Local Base Installation/Setup (starting with nopCommerce 2.40, .NET 4, and SQL Server 2008 R2)

  • Follow installation instructions that came with nopCommerce soure:  http://www.nopcommerce.com/docs/79/installing-nopcommerce.aspx
  • Initial run which sets up nopCommerce and most importantly, nopCommerce’s DB:
    • Set admininstrator nopCommerce account with admin email and password
    • Create nopCommerce DB
    • If you’re encountering this error at runtime, essentially you need a tax and shipping method defined, you can correct by following these steps:
      • Run app and log in with admin account above
        • Go into plugins and “Install” fixed rate tax provider
        • In plugins, “Install” Shipping.FixedRate
        • In plugins, “Install” Payments.PayPalStandard
        • Build and add Nop.Web\App_Data\InstalledPlugins.txt to the project so that it gets packaged later for Azure deployment
  • If you’re seeing first chance exceptions related to autofac you can modify ContainerManager.cs#Resolve(Type t)…. To use ResolveOptional() instead of      Resolve() to eliminate these autofac errors

Porting the nopCommerce DB to Azure SQL

  • Create SQL Azure instance and DB (Note the region as this will be used for affinity later if you’re using affinity)
  • Export scripts to create nopCommerce DB objects such as tables, functions, and stored procedures from the local DB build
  • Execute nopCommerce DB object scripts from previous step on nopCommerce DB in SQL Azure
  • Use SQL Server Import and Export Wizard to move data into SQL Azure nopCommerce DB by loosely following this article.
    • Note the varbinary(max) issue that may be encountered and resolution in this article.
  • Optionally create an application login.  References:  http://msdn.microsoft.com/en-us/library/windowsazure/ee336235.aspx and http://blogs.msdn.com/b/sqlazure/archive/2010/06/21/10028038.aspx
      • In master DB:
        • create LOGIN nopCommerceApp WITH password=’password’
        • create user nopCommerceApp from login nopCommerceApp
      • In nopCommerce DB:
        • create user nopCommerceApp from login nopCommerceApp
        • EXEC sp_addrolemember ‘db_owner’, ‘nopCommerceApp’;

Cloudification

  • Add local SQL Server user “nopCommerceApp” with password “xxxx” for the application to use.  Don’t forget to turn on mixed mode authentication and restart SQL Server.
  • After successfully running, add a solution folder “Cloud” to the solution
  • Add Azure Project “nopCommerceAzure” (heavily referenced:  http://shelastyle.net/blog/publishing-nopcommerce-2-0-to-azure/)
  • Delete any extra roles that may exist in the nopCommerceAzure project added in the previous step
  • Add Nop.Web as an nopCommerceAzure project Role
  • Add settings to Nop.Web Role in nopCommerceAzure project:
      • DataProvider = sqlserver
      • DBConnectionString = Data        Source=tcp:your_azure_DB_instance.database.windows.net,1433;Initial        Catalog=nopCommerce;User ID=nopCommerceApp@your_azure_DB_instance.database.windows.net;Password=password;Persist Security Info=False;MultipleActiveResultSets=True [Note the name “DBConnectionString” for the setting name]
  • Modify DataSettingsManager.cs to not obtain connection setting from file but rather from Nop.Web role in nopCommerceAzure project using Microsoft.Windows.Azure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue() Additionally changed the name from “DataConnectionString” to “DBConnectionString” to avoid getting Azure errors later.  DataConnectionString is a defacto keyword
  •  Remove Nop.Admin project from Presentation folder (to avoid duplication)
  • Change files under Nop.Web\App_Data\* to copy always
  • Showe all folders on Nop.Web
  • Include all plugin folders under Nop.Web\Plugins
  • Include items under Nop.Web\Administration (formerly hidden) except the following:
    • Nop.Web\Administration\Bin       – including all sub-elements
    • Nop.Web\Administration\obj – including all sub-elements
    • Nop.Web\Administration\Plugins – including all sub-elements
    • Nop.Web\Administration\Properties – including all sub-elements
    • Nop.Web\Administration\Nop.Admin.csproj
    • Nop.Web\Administration\Nop.Admin.csproj.user
  •  Exclude Nop.Web\Nop.Admin.dll from Nop.Web project
  • Add reference to AutoMapper (/packages/nopCommerceCustom/AutoMapper.dll) in Nop.Web (dependency)
  • If you encounter errors about routes already existing you’ll need to clear out the Nop.Admin.dll’s produced prior to Nop.Admin solution being removed.  Do this by  shutting down Azure emulator, clean project, fully reboot VS, and ensure these files do not exist after building:
    • nopCommerceAzure\csx\Debug\roles\Nop.Web\approot\bin\Nop.Admin.dll
    • nopCommerceAzure\obj\Debug\Nop.Web\bin
    • Presentation\Nop.Web\bin\Nop.Admin.dll
    • Presentation\Nop.Web\Nop.Admin.dll
    • Presentation\Nop.Web\Administration\obj\Debug\Nop.Admin.dll
    • Presentation\Nop.Web\Administration\obj\Debug\Nop.Admin.pdb
    • Presentation\Nop.Web\Administration\obj\Release\Nop.Admin.dll
    • Presentation\Nop.Web\Administration\obj\Release\Nop.Admin.pdb
    • Presentation\Nop.Web\Administration\Bin\Nop.Admin.dll

Publishing nopCommerce to Windows Azure

  • Create affinity group with the same region as SQL Azure
  • Create storage account using Azure management console called “nopCommerce” using the affinity group created in the previous step
  • Create hosted account using the same affinity group named “nopCommerceApp” with option not to deploy
  • For the initial install only, follow these publish instructions to move from Visual Studio to the cloud. After the initial install to Windows Azure, package in Visual Studio and then upgrade the hosted instance by uploading the package created by Visual Studio from the Windows Azure Management Portal.
Advertisements

About jamesfkinney

Hello! In my mind I'm a slightly shy, friendly geek. I enjoy having fun, socializing, technology, traveling, and all things related. These are my related musings.
This entry was posted in .NET, Computing and tagged , , , , . Bookmark the permalink.

3 Responses to nopCommerce 2.40 in the cloud via Windows Azure

  1. MarceQ says:

    Excellent post!

    I was struggling with this matter for a lot of days. Your hel is very well appreciated.

    Thank you!

  2. Mark Goodson says:

    Thank you! Excellent advice.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s