Feb 15, 2012

SQL Azure pricing reduced

As published today in the Azure Team Blog, pricing is reduced for SQL Azure (by about 50%). 5 GB are now 26$ instead of 50$.

Furthermore SQL Azure is getting more attractive for small data apps with the new 100MB option:

Database Size

Price Per Database Per Month

0 to 100 MB

Flat $4.995

Greater than 100 MB to 1 GB

Flat $9.99

-> 4 CHF/Mt for high availability, reliability and self-management.

See https://www.windowsazure.com/en-us/pricing/details/ for details.

Jan 30, 2012

SQL Server Database Restore for Dummies – like me

I got a SQL server (express) database backup (.bak file) from a customer to do a test against. In the past, I just restored from my own, previously existing databases, so I never came across the issue of restoring one from a complete different machine. Using SSMS I got the following error messages

The backup set holds a backup of a database other than the existing database – or

File 'Db' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.CUSTOMER\MSSQL\DATA\Db.mdf'. Use WITH MOVE to identify a valid location for the file.

The path does not exist on my machine. After browsing the web I found out the following:

  1. create a new and empty database named as the one from the customer (in this case ‘Db’)
  2. use a script to run

    RESTORE DATABASE [Db]
    FROM DISK = 'c:\theDbBackup.bak'
    WITH REPLACE

Jan 29, 2012

Excellence in Software Engineering Conference 2012 - in Zurich

 

This year the ESE conference 2012 will take place in Zurich April 24. and 25. – hosted by Zühlke Engineering AG.

That’s where software experts from around the world meet their peers and prominent speakers. The conference targets software architects, project managers, IT manager, process experts and all kinds of techies. Interactive discussion and talks are a major part of the two days.

image

There are three trendy tracks: Agile, Cloud and Mobile. See this for more details.

Jan 16, 2012

Struggling with Azure SDK Samples –> use Microsoft.ServiceBus.dll Version 1.6! or still 1.5?

Got some issues recently with the Azure SDK samples (e.g. RelayedConnectionSample with NetTcp, MulticastSample, etc.). SecurityExceptions were thrown, etc.

Until I noticed that the samples still reference the Microsoft.ServiceBus.dll in

  • version 1.5.0.0 under c:\Program Files\Windows Azure AppFabric SDK\V1.5\Assemblies\NET4.0\ instead of the latest one
  • version 1.6.0.0 which is now installed under C:\Program Files\Windows Azure SDK\v1.6\ServiceBus\ref

So you need to

  1. change assembly references to Microsoft.ServiceBus 1.6.0.0
  2. change .config settings to 1.6.0.0 to:

    <extensions>

      <bindingExtensions>

        <add name="netEventRelayBinding" type="Microsoft.ServiceBus.Configuration.NetEventRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

      </bindingExtensions>

    </extensions>

  </system.serviceModel>

 

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="Microsoft.ServiceBus"

                          publicKeyToken="31bf3856ad364e35"

                          culture="neutral" />

        <bindingRedirect oldVersion="1.0.0.0"

                         newVersion="1.6.0.0"/>

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

and it works again.

However, some of the samples did not with 1.6 but only with 1.5. Maybe I messed up with the latest SDK installation.

Azure Connect

Using Windows “Azure Connect” - a service from the Windows Azure platform – one can establish a protected network connection between enterprise computers and the cloud roles (E2C). This virtual IPsec network allows for:

  • easier migration of tiers of an applications to the cloud
  • tunnel firewalls, proxies, NATs
  • hybrid (cloud to on-premise) apps
  • various higher-level communication protocols
  • apps where the protocol might change
  • have high number of communicating endpoints
  • domain joins (some ActiveDirectory; logins)
  • remote administration, debugging and troubleshooting
  • DNS
  • etc.

Setting up Connect is a 3 step process. There is a tutorial showing all the details.

1. Get an activation token from the Azure portal and configure your Azure roles to use it.

image

image

Copy the token into your role’s properties / virtual network settings

image

Now you publish your Azure roles to the staging or production environment in the cloud. Wait until the service is ready and check that it appears in the portals “Virtual network” –> “Groups and Roles” and “Activated Endpoints”.

2. Enable local machines to connect to roles in the cloud. Install the Connect Agent on local machines. Copy the link URL to a browser, download the configured executable and run it. A system tray icon like the following should appear

image

3. Pair the local machines and Azure roles in a “Group” (network policy). In the portal click Create Group

image

The system tray icon should change to connected now.

Please note that ping will not work until you enable it in your role using a startup task script. From my limited home network I experienced some significant (first-hit) network delays

Pinging RD00155D3A622D [2a01:111:f102:121:858:cf20:a9dd:5639] with 32 bytes of data:
Reply from 2a01:111:f102:121:858:cf20:a9dd:5639: time=299ms
Reply from 2a01:111:f102:121:858:cf20:a9dd:5639: time=258ms
Reply from 2a01:111:f102:121:858:cf20:a9dd:5639: time=359ms
Reply from 2a01:111:f102:121:858:cf20:a9dd:5639: time=368ms

Ping statistics for 2a01:111:f102:121:858:cf20:a9dd:5639:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 258ms, Maximum = 368ms, Average = 321ms

Microsoft Azure SQL Data Sync

Azure Data Sync let’s you synchronize enterprise (on-premise) SQL Server (2005 and above) databases with SQL Azure databases – or several SQL Azure databases. There is a local agent and a cloud sync group service necessary for it to work.

This is the first preview from Nov 14 2011; let’s have a try.

In the management portal navigation tree go to Data Sync, select a subscription, a data center region,

image

You now have two options:

image

Let’s synchronize on-prem and a cloud SQL Azure database. The wizard leads you through the configuration of a sync group

image

image

image

image

Download and install the so called Sync Agent for the local server.

image

Then start the Data Sync Agent Preview from the start menu.

image

Now generate an agent key from the management portal and copy it into the local agent wizard.

image

Then register a SQL Server

image

to get

image

Back in the portal we add the agent to the Sync Group

image

Now we are half way through. Now let’s add an SQL Azure database:

image

Just creating a new SQL Azure database for this demo – and selecting it in Step 3 above.

image

In the following step (4) we configure the scheduling, and the conflict resolution (client or hub wins)

image

Select the on-premise SQL database

image

Click deploy now

image

Done!

Now, let’s see that it worked correctly. In the local Northwind database there are 2 people from Switzerland, add a row filter for Country = ‘Switzerland’. Then go the SSMS, connect the SQL Azure DB. There is a new dbo.Customers table now. Please also note the added tables for the change tracking. There are also some triggers and stored procedures added to your database. This may impact your runtime performance.

image

There are the 2 rows as expected:

image

That’s it again in the portal

image

This was actually super simple to setup. There are some best practices out there.

Negative point: there does not seem to exist an API or .NET library for scripted configuration and operation.

Nov 25, 2011

Fun Project: DotNetNuke module views

Last time I showed you how to create, build, package, upload and use a simple DNN module, developed in C# using Visual Studio
2010. Let’s get started by thinking (and writing down Smile) some requirements.

Requirements

Non-functional

R-NFR1 DotNetNuke 05.06
R-NFR2 ASP.NET 4
R-NFR3 local testability without DNN installation

Use Cases

As a client I want to:

R-U1 – Create an online account on the site
R-U2 – Log in and out
R-U3 – Choose a treatment
R-U4 – Choose a time/date
R-U5 – Book a massage 
R-U6 – Got sent an email confirmation
R-U6.1 with an outlook appointment attached to it
R-U7 – get shown my booked treatments in detail

As an administrator I want to:

R-A1 – Define treatments (duration, title, description)
R-A2 – Define time windows (opening or working hours)
R-A3 – Show (todays, etc.) bookings
R-A4 – Got sent an email with a client booking information
R-A5 – Manage accounts (list, add, edit, delete)

New Web Project

To separate DotNetNuke module stuff from booking web functionality I added a new ASP.NET web project to the solution

image

remove the generated pages, sub folders and strip down the web.config file to a minimum.

Now add a web user control to the BookingViews project

image

Telerik

Writing an outlook style schedule/calendar control in ASP.NET seems like a huge effort. Let’s get a commercial control library suite including a schedule control. As DNN already contains Telerik controls the evaluation was short. They have an excellent reputation when talking to colleagues.

Data Model

First let’s show the data access layer where the massage bookings and treatment offerings are persisted. Using the Entity Framework 4.0 model first approach, I create the following model:

image

The BookingEntry and Treatment entities were added in the model edmx in VS design view. However, the User entity was imported from the existing DotNetNuke database (table first). Adding some relations and I can take advantage of the DNN register/login/user functionality in my bookings.

View

Learning and configuring the module view took more effort. This is the resulting aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BookingForm.aspx.cs" Inherits="BookingViews.BookingForm" %>

 

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title></head><body><form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager>

    <div style="height: 527px; width: 827px">

        <telerik:RadScheduler ID="RadScheduler1" runat="server" Culture="de-CH" DayEndTime="19:00:00"

            DayStartTime="07:00:00" FirstDayOfWeek="Monday" Height="558px" SelectedView="WeekView"

            ShowViewTabs="False" Skin="Forest" Width="800px" WorkDayEndTime="19:00:00" WorkDayStartTime="07:00:00"

            SelectedDate="2011-11-01" DataEndField="End" DataKeyField="Id"

            DataStartField="Start" DataSubjectField="Subject"

            onappointmentcommand="RadScheduler1_AppointmentCommand"

            ontimeslotcreated="RadScheduler1_TimeSlotCreated"

            DataSourceID="BookingEntryDataSource" DataDescriptionField="Remarks"

            EnableDescriptionField="True">

            <ResourceTypes>

                <telerik:ResourceType DataSourceID="TreatmentDataSource"

                    ForeignKeyField="TreatmentId" KeyField="Id" Name="TreatmentResource"

                    TextField="Name" />

            </ResourceTypes>

            <WeekView DayEndTime="19:00:00" DayStartTime="07:00:00" HeaderDateFormat="dd.MM.yyyy"

                WorkDayEndTime="19:00:00" WorkDayStartTime="07:00:00" />

            <AppointmentTemplate>

                <span style        ="font-weight: bold; font-size: small">

                    <%# Eval("Subject") %>

                </span>

                <br />

                <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Resources/Calendar.png" OnClick="ExportOutlook" CommandName="ExportOutlook" />

            </AppointmentTemplate>

        </telerik:RadScheduler>

    </div>

    <telerik:RadAjaxManager runat="server">

        <AjaxSettings>

            <telerik:AjaxSetting AjaxControlID="RadScheduler1">

                <UpdatedControls>

                    <telerik:AjaxUpdatedControl ControlID="RadScheduler1" />

                </UpdatedControls>

            </telerik:AjaxSetting>

        </AjaxSettings>

    </telerik:RadAjaxManager>

    <asp:ObjectDataSource ID="BookingEntryDataSource" runat="server"

        DataObjectTypeName="My.DotNetNuke.Modules.BookingModule.BookingEntry"

        DeleteMethod="Delete" InsertMethod="Add" SelectMethod="GetAll"

        TypeName="My.DotNetNuke.Modules.BookingModule.Data.BookingEntryDataRepository"

        UpdateMethod="Update"></asp:ObjectDataSource>

    <asp:ObjectDataSource ID="TreatmentDataSource" runat="server"

        DataObjectTypeName="My.DotNetNuke.Modules.BookingModule.Treatment"

        DeleteMethod="Delete" InsertMethod="Add" SelectMethod="GetAll"

        TypeName="My.DotNetNuke.Modules.BookingModule.Data.TreatmentDataRepository"

        UpdateMethod="Update"></asp:ObjectDataSource>

    </form>

</body>

</html>

The control’s data sources are of type ObjectDataSource. BookingEntryDataSource and TreatmentDataSource both implement the IRepository<T> interface. This hides the EF stuff behind a façade and allowed better testability than the EntityDataSource:

    /// <summary>

    /// Interface to decouple entities from data access.

    /// </summary>

    public interface IRepository<T> where T: class

    {

        void Add(T entity);

        void Delete(T entity);

        ICollection<T> GetAll();

        T GetById(T entryWithKeyOnly);

        void Update(T entity);

    }

Note that I added the telerik rad scheduler, configured a week view, added some appointment resources and DataSources to be bound in the scheduler control.

And this is the final result:

image

Double clicking shows or edits the details of the appointment

image

I hope this 3-part series of my (hobby project) development “minutes” gave you some insight around DotNetNuke module development in Visual Studio using C#.

Azure AppFabric Caching ASP.NET Session State Provider – not working with 2 Instances in the local Compute Emulator

 

A customer asked me for help about this.

Introduction

Windows Azure AppFabric Cache is a subset of the Windows Server 2008 R2 AppFabric distributed in-memory cache (aka “Velocity”) and typically provides it’s services for ASP.NET session provider and output caching.

Enable Cache

To speed up your web apps performance you first need to enable this Azure feature on the management portal

image

Click New Service Namespace –> select Cache –> select your Azure subscription (for the billing) –> the region of the data center –> and a name.

Configure Web App to use the cache

In the management portal Properties copy your host name and authentication token

image

image

to your web.config <Configuration> section:

<configSections>

  <section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core" allowLocation="true" allowDefinition="Everywhere"/>

</configSections>

 

<dataCacheClients>

  <dataCacheClient name="default">

    <hosts>

      <host name="[SERVICE-HOST-NAME]" cachePort="22233" />

    </hosts>

    <securityProperties mode="Message">

      <messageSecurity

        authorizationInfo="[AUTHORIZATION INFO]">

      </messageSecurity>

    </securityProperties>

  </dataCacheClient>

</dataCacheClients>

 

<system.web>

 

  <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">

    <providers>

      <add name="AppFabricCacheSessionStoreProvider"

            type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"

            cacheName="default"

            useBlobMode="true"

            dataCacheClientName="default" />

    </providers>

  </sessionState>

 

Add assembly references to the Azure libraries

Microsoft.ApplicationServer.Caching.Client.dll
Microsoft.ApplicationServer.Caching.Core.dll
Microsoft.Web.DistributedCache.dll
Microsoft.WindowsFabric.Common
Microsoft.WindowsFabric.Data.Common

2 Instances

Configure your web role to use 2 instances. Otherwise you won’t notice the problem.

Attention

Make sure, you do not confuse with the Windows Server 2008 R2 AppFabric caching libraries. Use the ones under

C:\Program Files\Windows Azure AppFabric SDK\V1.5\Assemblies\NET4.0\Cache

Access the cache from code

In the following example from the AppFabric Lab Samples, store some shopping cart entries into the session

List<string> cart = this.Session["Cart"] as List<string> ?? new List<string>();

cart.Add(selectedItem);

Session["Cart"] = cart;

and read back

var itemsInSession = this.Session["Cart"] as List<string> ?? new List<string>();

Test it

Now when I start the app and add a product to the cart, stop the compute emulator, do an iisreset.exe and refresh the page – then I still see the product. This now comes from the Azure AppFabric Cache:

image

on instance 1. From the debugger:

Checkout on instance deployment16(44).AzureStoreService.MVCAzureStore_IN_1

Pressing F5 to refresh the page again in the browser I suddenly don’t see the product anymore

image

on instance 0. From debugger

Checkout on instance deployment16(44).AzureStoreService.MVCAzureStore_IN_0

Pressing IEs F5 again and again, shows or don’t shows the product …. ?!?

Problem

So the findings are, that the session cache basically works, but not in a (load-balanced) multi-instance environment on the local development fabric compute emulator! Depending on the web role instance (0 or 1) a different session cache is used.

It looks like each web role instance is still using default ASP.NET in-proc session state, meaning you'd have different session state on each instance.

However, the session id is the same

image

I made sure the default in-proc session state provider is removed by commenting it and <clear/>ing the providers list:

<!--<sessionState mode="InProc" customProvider="DefaultSessionProvider">

  <providers>

    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />

  </providers>

</sessionState>-->

<!-- If session state needs to be saved in AppFabric Caching service, add the following to web.config inside system.web. If SSL is required, then change dataCacheClientName to "SslEndpoint". -->

<sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">

  <providers>

   <clear/>

    <add name="AppFabricCacheSessionStoreProvider"

          type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"

          cacheName="default"

          useBlobMode="true"

          dataCacheClientName="default" />

  </providers>

</sessionState>

All over again – it works in the Cloud

Not sure I did something wrong in the Lab sample – I started all over again from scratch with a simple app that stores the text box value into the Session[] state and reads it back using the buttons. Value/InstanceId/SessionID are written to the label below.

Same problem on the local fabric – BUT …

… storing from IE’s first tab the value “m5” to web role instance 0 in session 5WJJ:

image

Reading back from IE’s second tab the value “m5” from web role instance 1 in session 5WJJ:

image

gives me what I expected.

Help

As I understand this should not be the case? Seems to be an issue in the local compute emulator using the AppFabric cache service! It works in the cloud – but still makes local testing hard. Any ideas?

Nov 23, 2011

Fun Project: DotNetNuke module development

This post shows you how to create a DNN module in C# using Visual Studio 2010 – from beginner to beginner – to make expectations clear.

Requirements

In time with the site going live, new requirements popped up:

  • online bookings of treatments by clients
  • manage massage treatments through my wife
  • booking selected treatments using a kind of schedule/calendar view (clients) in predefined time windows / opening hours (admin).
  • email confirmations (client and admin)

I found no module for these Sad smile.

Visual Studio Project Template

As Visual Studio and C# are my friends, I downloaded the DNN template from dotnetnuke.codeplex.com and added a new project to my VS 2010 solution:

image

which added the following structure:

image

changed to .NET framework to 4.0 and added my custom namespace

image

Performing a Release build

image

Packaging

Right clicking the module project in the solution explorer and choosing “Build Deployment Package” creates the necessary CMS upload package BookingModule_00.00.01_Source.zip in the packages sub folder.

The packing script error:

Error    1    The target "Package" does not exist in the project.   

can probably be ignored. It indicates the build script references the solution file rather than the csproj project file.

image

Note the packaging scripts are included in your DNN module project folder “BuildScripts”

image

 

Host Login

When I created the DNN site within my hoster’s portal, I got asked to create two login account credentials:

  1. Administrator: create pages, add installed modules to pages, change skins and styles, etc.
  2. Host: same as the administrator, but with additional rights, one of these is installing new modules

So you must log in with your host account

image

to see the additional site menu items “Admin” and “Host”. Clicking host shows the Extensions icon:

image

to see the DNN framework (version), Authentication System, Container, Library, Module, Provider, Skin, Skin Objects and in the bottom right pane the command to install a new module Install Extension Wizard:

image 

selecting and uploading the previously built release package, next, booom!

Install Extension

Upload Results
If you have reached this page it is because the installer needs to gather some more information, before proceeding.

Error reading the zip package - see below

StartJob
Reading Installation Manifest file

Info
Reading Package Manifest - Module - BookingModule

Failure
Install aborted - The module being installed is not compatible with your host application version ( an upgrade is required )

I spent some time googling for answers, found some useful hints, saying the module is not compatible with my DNN version. But my problem remains: I cannot update my CMS with my hoster and I’ve got the latest Visual Studio template!? Hm. The solution was in the VS project DNN manifest file (project.dnn):

<dotnetnuke type="Package" version="5.0">

  <packages>

    <package name="BookingModule" type="Module" version="00.00.01">

      <…/>

      <dependencies>

       <dependency type="CoreVersion">06.00.00</dependency>

      </dependencies>

You need to delete the dependencies node, rebuild, repackage, upload again:

image

Yeah.

image

You can now add it to you page / pane as host –> edit mode –> common task –> add module

image

and when the module has the same rights as the page, then you can see it. There’s a context menu added

image

that let’s you switch to an “Edit Module” view or “Settings” view. Do you remember the three .ascx asp.net user controls in the above module project?

I hope this blog post gave you some overview of DotNetNuke module developments to get started with, including some pitfalls (I have fallen into).

Next time, I plan to show you the development of the web stuff, including the database model, data access, UI.