Wednesday, 21 April 2010

Microsoft's Free Silverlight 4 LOB Training Course (and dealing with possible Database Issues)

I'm often asked for advice on how best to learn Silverlight, and with the release of Silverlight 4 last week folks are keener than ever to get to grips with the technology, particularly for writing line-of-business applications.

At the time of writing, the only book available for Silverlight 4 is Microsoft Silverlight 4 Business Application Development. Although the book advertises itself as a 'Beginner's Guide', and has been written and technically edited by folks boasting the usual expert 'MVP' and 'Insider' credentials, I would NOT recommend this book for beginners, despite the pedigree of the authors and the basic step-by-step and subsequent analysis structure which I like. The book went to print before Silverlight 4 had RTM'ed, and contains a number of, frankly, quite basic errors that will only confuse those new to Silverlight. These include claims (and screenshots) implying that Visual Studio 2008 can be used to build Silverlight 4 applications, that Blend 3 is a 'required tool' for Silverlight 4 development (Blend 3 does not support Silverlight 4), and a confusing set of step-by-step exercises where the authors and reviewers don't seem to have realised that when working with font sizes Blend 4 (which has to be used for Silverlight 4) works with point sizes which are different from the underlying Silverlight XAML pixel sizes), or that if you put a TargetType of UserControl on a resource style Blend isn't going to then let you use that same style on a button!

Microsoft are obviously aware of the 'learning curve' problem with Silverlight 4 and have launched a free Silverlight 4 training course. The course includes 8 modules around 'Building Silverlight 4 Business Applications' which they estimate comprises 2 days worth of training, and has been written and presented (it includes videos as well as step-by-step follow along exercises) by Ian Griffiths, who has an excellent reputation as a Silverlight and WPF trainer (his Silverlight 3 'on demand' training course for Pluralsight looks very good indeed, from what I saw of it, and apparently a Silverlight 4 version of that 'soup to nuts' material is on its way if you sign up for Pluralsight training).

Ian and Microsoft are keen to point out that the free training course that's been provided through Microsoft's Channel 9 outlet is NOT a 'soup to nuts' Silverlight training course, and that there are assumptions you've done at least some of the 'Getting Started' Silverlight tutorials available at the Microsoft site. However the course does introduce the MVVM pattern, make good use of WCF RIA Services and in its last module even introduces MEF - all stuff that typically gets missed out from basic Silverlight training. Last night I decided to give it a quick look.

Unfortunately I hit problems almost immediately because of the configuration of my local machine, and so the main purpose of this blog entry is to document how to fix these problems for those who may find themselves hitting the same issues.

I do still have one outstanding problem in that Visual Studio 2010 never seems to 'remember' the changes I've made to the database connection string, and requires me to make the same modifications every time I restart it. To me this looks like a bug (I've made the mods and happily run new builds that work - why is Visual Studio 2010 ignoring them on restart?) but if anyone knows different I'd appreciate a reply in the Comments section of this blog post.

Very early on in the first hands on lab (actually Module 2, since Module 1 comprises a simple video introduction to the course and nothing more) you are asked to add an .mdf database file to your project. When I attempted to view this database using Server Explorer a nasty, and somewhat confusing error dialog appeared, implying that the database file was too 'new' for my installed software (SQL Server 2008 with all the latest service packs and updates applied):

Error message when SQL Server 2008 Express isn't installed

It turns out that his message is the result of the database file being opened with SQL Server 2005 Express edition, when it is a SQL Server 2008 Express edition database. Although I'd updated my machine with an installation of SQL Server 2008 some time ago, and then installed Visual Studio 2010 I'd never installed SQL Server 2008 Express Edition.

The fix appeared relatively straightforward: change the connection string to use the installed version of SQL Server 2008 rather than the version of SQL Server 2005 Express Edition it seemed to have decided was the preferred option. This is achieved using the 'Modify Connection' context menu option in the server explorer:
The 'Modify Connection' context menu option

The resulting dialog box has an Advanced properties tab which you display by clicking on the Advanced button:
Dialog giving access to the Advanced properties

From here it's a simple matter of selecting the appropriate SQL Server instance from the drop-down list box. The dropdown list box initially shows the SQL Server 2005 Express instance it has decided to use:
SQL Server instance has been set to SQL Server 2005 Express

It's a simple matter to change it to the SQL Server 2008 instance:
SQL Server instance reset to SQL Server 2008

However this then introduces a new error when 'OK' or 'Test Connection' is selected, as shown below:
User authentication flag error when using full version of SQL Server 2008

It seems there are some ASP.NET user authentication security precautions with the developer/full versions of SQL Server 2008 that aren't there with the SQL Server 2008 Express edition, causing this error to be displayed. The only solution to the problem appears to be to install SQL Server 2008 Express edition as well as the full edition already installed. Make sure you download the Sp1 version of the Express edition (which can be found here to avoid warnings about an out-of-date incompatible version) and be prepared for a restart before the install will fully run.

Once you've installed the Express Edition you can change the connection string, as shown previously, to point to the newly installed Express instance, and happily proceed with what looks to be a fun training course.

Setting the connection string to the newly installed SQL Server 2008 Express instance

Now when you click on the 'Test Connection' button the errors have all gone away:
Finally - a good connection (until you restart Visual Studio 2010)

As indicated earlier, the only problem is that every time you restart Visual Studio 2010 the database connection string seems to reset itself to the SQL Server 2005 Express instance, causing the initial 'version' error that kicked off this whole blog entry.

If anyone knows how to make this error go away for good I'd be happy to hear from you (and will update this blog entry accordingly).

No comments: