Skip to Content

jlopez's blog

Microsoft Lightswitch - Round 1 of testing.

In every company there is more demand for applications than there is ability to create those applications. In the past, a workgroup in a Microsoft shop might create their own workarounds the limits of IT resources by using tools such as Microsoft Excel, Access or even a little bit of VB.NET code.

Excel is great for simple reporting, charting and even light data tracking as a intermediate step before the main line of business applications. However it quickly runs against the wall if the data being worked with is more complex than a few tables and look-ups.

Once that wall is reached, Access provides a great stepping stone for data management and feeding Excel data for charting and reporting purposes. With a fairly simple parent/child linked forms, it allows going to the next level with data, unlocking the power of a full relational database.

Access, however, is "opinionated software" and it is challenging for non-programmers to make custom user interfaces that don't work the "Access Way". (It is possible to make completely custom experiences in Access, but it somewhat defeats the purpose of the provided form editors.)

Additionally, while .NET languages can talk to Access, it isn't the native experience. After working with C# for years, VBA is a painful step backwards. Finally, Access never did play well with the Internet, having some half-hearted web interface options that I have not seen deployed to production in any serious capacity.

Enter Microsoft LightSwitch. In many ways I now think of it as "Access for Intranet and Web". LightSwitch is opinionated software, like Access. It goes even farther than Access in that you can't edit the layout of a data page explicitly. Instead, the order of fields is specified and the layout engine takes care of the actual presentation.

This sounds incredibly limiting, but we just deployed our first LightSwitch application. The process of connecting to our SQL databases was easy and had some surprising benefits. Like many organizations we have multiple applications with distinct databases. Normally we use the "linked server" feature to allow cross database access to tables, but LightSwitch understands the concept of federated data access, going so far as allowing the definition of virtual foreign keys across data sources. This made making a cross database application actually easier than our tradition method.

More importantly, after building a quick prototype example I was able to hand the tool off to a non-programmer who was able to quickly put together new needed data access pages in just an afternoon. Best of all, the underlying programming environment is Visual Studio 2010 with C# or VB.NET, retaining all the benefits of the modern development environment.

The output from LightSwitch is a Silverlight application. It can be deployed as to websites (although the user of the application must have Silverlight installed, which isn't as common as Adobe's Flash, for example). For Intranets this is much easier to ensure. Alternatively, it can be deployed as a desktop application (which is nothing but a container for the Silverlight code, so Silverlight is still a requirement). I would have preferred a native Windows Presentation Framework (WPF) application, but it does ensure that all deployments have the same user experience.

Overall our initial experience has been good. The only thing I do see as a problem going forward is that LightSwitch does not seem to have a way to integrate existing .NET business logic modules. This makes sense in that POCO (Plain Old CLR Objects) business logic modules don't have a defined interface. I have seen some posts where people have usedWindows Communications Framework (WCF) to access business logic, but I have not tried this process yet.

Still, LightSwitch has a place in the toolbox for quick and dirty data access projects. I see it replacing Access in this role in our shop, if only because we can leverage our C# know-how and work with Federated databases far easier than any other tool. Recommended, with those noted caveat.

Accessing shadow copies

Previously we talked about the fact that the backups created by the Vista, Windows 7 and Windows Server 2008 backup tool are actually virtual hard drives which can be mounted for access via drive letters. It is also possible to mount shadow copies as well, as documented at http://blogs.msdn.com/b/adioltean/archive/2005/01/20/357836.aspx

There are a couple scenarios where this is useful. The reason I wanted access was errors in a machine's logs that read The file system structure on the disk is corrupt and unusable. Please run the chkdsk utility on the volume \Device\HarddiskVolumeShadowCopy[N]. To allow chkdsk to run, I simply mounted that shadow copy, the details of which I found using vssadmin list shadows.

The code as presented in that blog creates new shadow copies. As we wish to access existing copies, the key is understanding what the line %~dp0\vshadow.exe -el=%SHADOW_ID_1%,%DESTINATION_VOLUME% is doing.

We can mount a shadow simply by dropping to an administrative command line and issuing vshadow.exe -el=[show copy guid] z: (vshadow.exe is available in the SDK mentioned in the original article: http://www.microsoft.com/download/en/details.aspx?id=23490)

A modern version of the copy scenario the original blog mentioned can be found here: http://tranxcoder.wordpress.com/2010/01/26/using-volume-shadow-services-to-copy-locked-files/ and an API for accessing shadow copies in C# can be found at http://alphavss.codeplex.com/

Resetting networking in XP

I had a machine with slow response in Remote Desktop. I found this article, but the primary solution was regarding Windows Vista/7 automatic configuration.

However, in the comments I found the following sequence, which does seem to reset troubled adapters even on XP:


netsh winsock reset
netsh int ip reset
netsh interface ip delete arpcache
netsh winsock reset catalog
netsh int ip reset reset.log

Remove the OEM wallpaper.

Many machines come with a fancy wallpaper when you turn them on. Locally, this isn't a problem... however, when you connect via Remote Desktop, you get to watch this wallpaper download slowly, every time you connect. (You can disable the *actual* wallpaper that the desktop shows after logon in the RDP client, but this splash-screen isn't disabled when you do so.)

The fix is easy, delete the registry key: /HKU/.default/Control Panel/Desktop/Wallpaper. Alternatively, pointing it at a BMP that doesn't weigh in at 1MB. Either way, your remote desktop logon will be *much* faster.

Installation List

When I repaved my development machine, what got reinstalled... and why? Here is my list, in alphabetical order.

Adobe Web Premium 5.5 Suite, from which I primary use Acrobat X, Illustrator, Photoshop, Flash Pro and Dreamweaver.

Bulk Rename Utility, the ugliest UI in the world, but priceless when you need to rename some crazy batch of files in some regular way.

Carbonite, to access my online backup (and eventually it will be unfrozen and backing up the new install).

DevExpress Refactor! Pro/CodeRush, for code efficiency.

Filezilla, for GUI ftp access.

Google Chrome, as my primary browser.

grepWin x64, bringing the power of Grep to Windows.

KeePass Password Safe, because using the same password twice is a bad idea.

Logitech Webcam, for meetings.

Microsoft IIS Webserver, for development.

Microsoft Office 2010, mostly for OneNote, which I'm finding replaces my old mind mapping software.

Microsoft Silverlight, for development.

Microsoft SQL Server 2008 Developer's edition, for development.

Microsoft Visual Studio 2010, for development.

Microsoft Visio Pro, for quick diagrams.

Microsoft LightSwitch 2011, for evaluation.

Mozilla Firefox 5, for the rich plugin environment which turns it into a power web development tool.

Notepad++, for quick and dirty text editing.

QuickBooks Pro 2011, for accounting.

Skype, for the IM features.

SQL Compare/Data Compare, Redgate's excellent database tools.

Synergy, to link my main keyboard and mouse to the notebook and server.

Terminals, to manage the many remote sessions I use.

TortoiseSVN, to manage the SVN repositories. I do wish there was a good SVN UI that didn't attach to the explorer, as I find the performance slower than dedicated tools and the icon overlay fights with Carbonite.

URecover for Windows Backup, which I used prior to finding the scripts for accessing the Image Backup internal data.

WhoCrashed, useful for checking bluescreen dumps while I get the drivers sorted out (which I seem to have done).

WinHTTrack Website Copier, for mirroring content so it can be used in unit tests when making changes to sites.

WinRAR 4, because there is the occasional RAR file that needs to be opened.

Backups, backups, backups.

Computer hardware will fail eventually. We all know this from experience and instinctively. That such complex systems work as reliably as they do should be the amazing thought, not the idea that someday they will crash.

Yet one of the recurring plea's I get is from people who failed to back their data up. The story itself varies remarkably little each time the call comes in: "please help, I lost [everything/the last 6 months/some important project]".

There are some ways to recover data from a broken computer, but the most common failure mode of a modern machine is a corrupted hard drive, which in turn requires specialized software to recover. In the worst case scenarios, a company like OnTrack needs to utilize their amazing hardware lab to recover the data (a service that will run hundreds if you are luck, thousands if you aren't).

So when my primary desktop failed, I felt I was prepared. My systems are backed up to:

1. A system image on a removable hard drive, via Windows 7 System Image Backup (which is built into Windows 7.
2. A network server keeps a copy of my data, via Second Copy.
3. An internet service designed for remote backups, via Carbonite.
4. A notebook I use to be able to quickly spring back to productivity, also via Second Copy.

And yet, it took me a weekend to be back on my feet properly and two more days to bring my desktop back up to speed. What happened?

The first problem was that the system image being created when I did a "successful" System Image Backup was backing up... corrupted system files. This is a completely unexpected result, but the devastating truth is that the Windows 7 image backup has no verification step. Rolling back to a month earlier image (I take a full image weekly) showed that even that copy had log files filled with "warnings" about failed shadow copies, while the backup itself reported "success".

This is a lesson in reading log files as much as not trusting what software tells you. The backup software should have never accepted failed shadow copies as a source for backups, but there it is.

With the realization that I was going to be a month out of date and still running a version of Windows throwing massive warnings, I decided a re-install was in order. Getting Windows 7 back online was painless enough via the installation media, but the big pain was the massive amount of software that I had to re-install.

Office Suite, Development Tools, Database, Utilities, Graphics Suites and more. Some of it I have still not reapplied because it isn't necessary yet. Then there was the data... how was I going to get it back the fastest.

That is when I discovered what windows image backups really are... virtual machine hard drive images! Better yet, they can be mounted quite easily via a quick script, I found the best description at How-To Geek: Mount and Unmount a VHD File in Windows Explorer via a Right-Click.

I ran a check-disk on these virtual drives and found that no *data* had been lost. I was quickly able to retrieve my large databases and other important files, but better yet, I moved those files to a safe place so I can use them in the future as well.

Even so, four days were either lost or less productive due to the amount of reconfiguration, recovery and adjustments that had to be made, all because I trusted the system image was actually making a useful recovery point.

SEO, living with it.

SEO companies have created an interesting dilemma. On one hand, they have created a market for their services which is self perpetuating: a company without good SEO is at a disadvantage compared to one with strong SEO behind it, which creates more demand for their services. The amount of disadvantage depends on the companies business.

Impulse buys for products in a narrow category may be profoundly impacted by search rank as that may be the primary customer acquisition technique. On the other hand, companies providing highly specialized services to corporations that do due diligence before purchases are probably fairly immune to search rank as long as they rank on their own trademarks.

On the other hand, there are only a limited number of things that can be done to a website before it is "optimized" 95% of the way and further effort is going to yield poor return on investment. That is when people turn to "link building". Link building is one of those practices that falls into a grey area. Overly aggressive link building campaigns can lead to results like The Dirty Little Secrets of Search.

The specific rules that most SEO companies like to play fast and loose with are Little or no original content and Cloaking, redirects and doorways. At the end of the day the goal of these techniques is to allow "non organic" linking to be hidden from the search engine enough that they won't be discounted. The problem of course is that when you are too successful, you end up like JC Penny: trying to do damage control on their reputation and search position.

A clearing house for techniques that I really like is the link building wiki. The opinions linked from that page are varied and understanding the sum total of those links will put you in the head of the SEO professionals, minus the worst practices.

SEO isn't going to go away, so living with it, understanding it and coming to peace with the techniques that you can live with and understanding that avoiding those that you can't will go far farther than most SEO firms which focus heavily on building links inorganically (and thus, eventually, drawing the eye of Google's spam team).

Wave in a box continues to disappoint.

Wave in a box was supposed to allow people to run their own Wave style servers due to the fact that Google abandoned the project. They provided tools for exporting existing waves, but the progress on Wave in a Box appears to have completely stalled, which is disappointing.

I know most people felt it was too different and had no significant benefit, but having used it to manage some in-house projects with a distributed team I can say that it did come with a set of benefits that were too often overlooked.

The biggest one was the fact that, unlike e-mail, the discussions and documents in a Wave were sharable with a team and everyone could see the current state. The past could be edited, but a history of that past remained visible so any vandalism or mistakes could be undone. Yet it had the immediacy of chat and a shared document being edited in real time.

Once you got past the quirks, it was addictive. Sadly, I have tried at various points during Wave in a box's development to run a server and have always come away disappointed in the fraction of features that are implemented and the horrible crash rate.

The current build (development branch as of 2011-06-09) can't even store a wave. The system throws an error of "Received overlapping submit requests to subscription" and only the first few characters survive. It appears to allow you to continue, but it actually ignores all input past that point.

This error appears to be time dependent: if I type slowly I only save two or three characters. At my normal rate, two or three words. Using cut and paste I can actually "beat the clock" and get more in, but that seems to defeat the purpose of an editor and anyways it crashes more seriously after I add a reply to any content I slip in.

I wish I could find a competent wave replacement, but nothing I have found combines the immediacy *and* the persistence of Wave.

TransactionScope for unit testing complex database access code.

Since .NET 2.0 came out, the TransactionScope class has provided an excellent way to manage complex transactions in the simplest way possible: using the scoping rules of the language itself. The basic method for using a TransactionScope couldn't be easier:

using (TransactionScope scope = new TransactionScope())
{
    ... your transactional code here ...
    scope.Complete();
}

An overview of TransactionScope can be found on MSDN.

The idea here is that when you fall out of the scope of the using block the transaction will COMMIT or ROLLBACK. If you call scope.Complete(), the transaction will commit. If you fail to make that call then leaving the scope of the using block will rollback all the work done.

What makes this so amazing is that anything that implements the System.Transaction infrastructure will respect these rules, so you are not just able to work with database providers (which are the most common implementer of System.Transaction) but MSMQ (Micrsoft Message Queueing) and other enterprise components.

There is a trick that is so blindingly obvious that it eludes some programmers for years: the ability to use TransactionScope to test database access code.

The primary problem with testing database logic is that you need to reset the database back to its original condition before you can test again, yet the databasic logic that really needs testing is very complex and includes things such as triggers, constraints and other database level resources that are difficult to mock out.

Enter the TransactionScope: simply wrap your hair raising database logic within it and you gain the ability to make changes to the database, verify the changes are correct and then undo those changes seamlessly. Triggers will fire, constraints will be respected and more importantly all those things will vanish when you fail to call .Complete().

TransactionScope. It isn't just for failed operations.

Junction Trouble? Try Link Magic

Link Magic is one of those programs that has a very narrow focus, but if you need what it does, you should download and try it out.

In my case, I was receiving mount point errors from a Windows 2003 R2 server. To find the possible problem I used Link Magic to list all of the Junction Points, Symbolic Links, Mount Points and other operating system links, looking for any with a broken entry. Junction Magic also removes and creates links in a simpler manner than the traditional command line methods.

Syndicate content