Using the Sterling database in your Windows Phone 7 App

I am working on a Windows Phone 7 app (stay tuned. Will reveal soon) and needed a database to manage my data. As you may be aware, the current release of Windows Phone 7 does not have a native embedded database, unlike SQLite for the iPhone platform. A Google search landed me this proof of concept project that makes SQLite available for Windows Phone 7. Coupled with the SQLite Manager Firefox add-on, it looked like I had everything I need for my data storage solution. This blog post, which outlines the creation of a helper class, made using SQLite in my app even easier.

But then I hit a roadblock. No matter what, I could not get my app to talk to my SQLite database. I could not get rid of the “Unable to open database file” exception. So, I gave up and resumed my search. This time, search revealed Sterling, an Isolated Storage database for Windows Phone 7 with LINQ support created by Jeremy Likness. Perfect.

The codeplex home of Sterling has everything you need to start using this excellent storage solution for your Windows Phone 7 app. Source, sample code, documentation (MS Word and PDF formats). You get everything. However, I did run into a few hiccups and hopefully my findings below will help you get past any blocks. This is not a replacement for the excellent documentation for Sterling. I am filling a few gaps that will help those not familiar with Silverlight and/or Windows Phone 7 get Sterling setup quickly.

Here’s how you do it.

1. Download the latest Sterling changeset (69384 as of this writing) from here and extract the zip file to a folder of your choice

2. The following folders will be extracted

Folder Name Description
BuildProcessTemplates Templates used by TFS build process
doc Sterling documentation in Word and PDF formats
src Sterling source code and sample projects

3. The src folder contains the following sub-folders

SetupSln Visual Studio setup solution
SterlingSln Sterling source for Phone and Silverlight projects, samples

4. The SterlingSln folder contains the following

SterlingExample A sample Silverlight project demonstrating the use Sterling
SterlingExample.Web ASP.Net web project that hosts the SterlingExample
WindowsPhoneSterling A sample Windows Phone project demonstrating the use of Sterling
Wintellect.Sterling Sterling engine for use in Silverlight applications
Wintellect.Sterling.Test Visual Studio test project for Wintellect.Sterling
Wintellect.Sterling.WindowsPhone Sterling engine for use in Windows Phone applications

5. The SterlingSln folder also contains the following Visual Studio 2010 solutions

WindowsPhoneSterlingSln.sln VS2010 solution with a Windows Phone sample app (WindowsPhoneSterling) and Windows Phone Sterling engine (Wintellect.Sterling.WindowsPhone)
Wintellect.Sterling.sln VS2010 solution that loads the Sterling engine for Silverlight (Wintellect.Sterling) and a VS2010 test project (Wintellect.Sterling.Test)
Wintellect.Sterling.WindowsPhone.sln VS2010 solution that loads the Sterling engine for Silverlight (Wintellect.Sterling), VS2010 test project (Wintellect.Sterling.Test) and the Sterling engine for Windows Phone (Wintellect.Sterling.WindowsPhone)

The Windows Phone 7 sample app that demonstrates the use of the Sterling engine is WindowsPhoneSterlingSln.sln. In my opinion, this solution file should be renamed as WindowsPhoneSterlingSampleSln.

6. Now that we have an idea of what we get in our download, it’s time to use the engine in your project. You can either build Wintellect.Sterling.WindowsPhone.csproj and reference the generated DLL in your Phone app or add Wintellect.Sterling.WindowsPhone.csproj to your Windows Phone solution and opt for Project reference.

7. Peruse the Quick start sections in the documentation to understand how to use Sterling. The “Using Sterling” section outlines the required steps.

And here is where I stumbled.

The sample code following the “Using Sterling” section shows a service class that can be created in your app to ease the use of Sterling. The caption states that the code is from the Sterling Phone example project. However, if you search WindowsPhoneSterling.csproj or WindowsPhoneSterlingSln.sln, you won’t find the service class. A sample service class (SterlingService.cs) is included in SterlingExample.csproj. But that project is a classic Silverlight project and not a Windows Phone 7 project. I was confused. If you look in the WindowsPhoneSterling.csproj sample project, Sterling engine usage code is in App.xaml.cs file. The code in App.xaml.cs follows the steps outlined in the “Using Sterling” section from the documentation. And yet, the sample code that follows service class, for example, code in “Saving your class” section, references the DatabaseService class.

So, after spending a couple of head-scratching moments this is what I comprehended.

The Sterling engine can be setup in your Windows Phone project in two ways

1. Follow the steps outlined in “Using Sterling” section from the documentation and sprinkle code in the various Application service methods (activating the engine in the Application_Launching event handler, deactivating the engine in the Application_Deactivated and Application_Closing event handlers, etc)


2. Create a service class that performs the activation, database registration, deactivation and disposal.

Personally I like option 2. Much cleaner code and I don’t have to monkey with various Application service event handlers. Also, I don’t have to declare a public property in the App class to allow access to the current instance of the database. The service class exposes a static property named “Current” using which you can access the current database instance.

Once you create your service class (complete implementation sample can be found in the documentation for Sterling), you invoke it in your App.xaml. Here is the code that you need to add to your App.xaml

1. Add the namespace declaration


Replace “yourTag” above with whatever fancies you and “ServiceClassNamespace” with the namespace of your service class

2. Add the service declaration markup to the <Application.ApplicationLifetimeObjects> node in your App.xaml file like so

<yourTag:YourDatabaseService />

When your Windows Phone app starts up, the methods (StartService, Starting) on your service class will be invoked auto-magically. Likewise, when the app is deactivated or shut down, the appropriate methods (Exiting, Exited) will be invoked again. As long as you follow the conventions,

So, there you have it. Hopefully this has been useful. The Sterling database engine is a fantastic Isolated storage solution for your Windows Phone App. Very few moving parts and dead easy to use. Jeremy Linkess has done a very good job of creating an ingeniously simple solution.


This Developer’s Life – A quick review of the podcast

Being active on the twitterverse, I learned about Rebel (Rob) Conery’s This Developer’s Life, a brand new podcast almost as soon as it was launched. My expectations were very high. I highly respect Rob for all that he does, especially speaking out and, being opinionated. I had my own podcast which was inspired by the now off-air “The Brain Food Podcast” from NPR. Although my podcast content was not original, it still takes a lot to put one together. I listen to NPR’s This American Life and love the format and, of course who doesn’t love Ira Glass?

As I started to listen to the first story (Sara J Chipps) in the first episode, disappointment started to set it. The composition was so poor, the music fade ins and outs were so jarring, it was unbelievable. Story telling stopped at odd points, Rob’s voice came in. It was utter confusion. I did not expect this from Rob. I just couldn’t believe that Rob had done such a poor job. Without quality a podcast will die soon. Rob is a respected software developer and anything from him is guaranteed instant audience. I didn’t want the podcast to fail, because the idea is a great one. I wanted to stop and forget about the podcast.

I persisted. And, I was rewarded. By the time the second story was about a minute in, the quality had improved so greatly, I had to rewind and listen to the first story again just to be sure. I have not listened to the latest updates and cleanups. By the end of the second story, everything was different. The story cuts were apt, the background music just right and, Rob’s voice started to sound like Ira’s.

Starting with episode 2, one can be forgiven if they think This Developer’s Life was actually put together by NPR and Ira is actually voicing it. All the irritations of the first story in episode one are gone. The song selection is superb, greatly matches the story and the story telling stops are the right spot.

Rob, thanks for putting together such an excellent podcast. Love the idea and the stories you bring to life.

It’s only fitting that just like NPR is listener supported, we make This Developer’s Life listener supported too and send it our contributions. Who’s in?

Announcing (beta)

After working on it for about a week, I am announcing the open beta of a new website that lets you create Microsoft Tags of your twitter Id. Please check out

What is unique about

Well, you can certainly create all kinds of tags at Microsoft’s tag website, but you need to create a Windows Live account. If you would like to check out the power of Microsoft Tags, create a Windows Live account and play with it. But, if you are not too keen on creating a live account, will get the job done fast and easy. creates one type of tag. A tag that browses to your twitter page.


All feedback welcome.

It takes guts to do Agile scrum

The latest in software engineering practice is Agile,  scrum,  XP etc, etc.  Everyone seems to be doing it. Everywhere you look, this new trend seems to be in rage. Don’t get me wrong. This post is not dissing the practice. If done right and pragmatically, Agile is the way to go. The theory is good. No not just good, but great! The issue is practice. It is one thing to come up with a good idea, but without execution, that’s what it is – a good idea. End of story.

In my opinion,  agile scrum does not work. Having made that provocative statement, let me qualify it. Agile does not work if the team practicing it does not have guts. You need passionate, self-motivated people to make agile a success.  Else, all you are doing is going fast nowhere and telling stories. Scott Hanselman‘s team is an example of a team that can successfully do agile.

Here are some of the tenets of running an Agile team

1. An agile team may not have a team lead
In theory this is good. If everyone is equally motivated and smart, you dont need a task assigner or team leader. The team understands the needs and just gets it done. Team members look at the scrum board, pull tasks, swarm around blocks and keep moving the stones up the pyramids. Great things are accomplished by great teams. However, there are only so many good people. The minute you put more than 2 mediocre people, you bring in politics.  People start finding all kinds of excuses to why something cannot or could not be done. For mediocre people only sticks work.

2. Every team member is accountable to the team. Everyone is empowered.
Again, a great idea. If everyone is honest, no one will feel threatened. Smart people treat one another with respect. To use the cliche, with empowerment comes responsibility. Most agile teams start out to have daily stand-up meetings. However these meetings pretty soon devolve into status meetings which waste everyone’s time. Everyone shows up. Blurts out what they did yesterday, what they might do today and there never is any block. None whatsoever. No one questions anything. Just get it over with. When it’s everyones responsibility to be accountable and call out, it becomes no one’s responsibility. You scratch my back and I’ll scratch yours. This is why you need gutsy team members. Team members who have the guts to call out others and team  members who have the guts to take critisism.

3. An agile process will weed out weak players because process shines the light on such players
For this to really work, you need honest, motivated people. Put together a bunch of mediocre people, and you will get what you  measure. Everyone will start working toward satisfying the measurements. The manager uses a magic formula to deem that a team of 5 people can deliver X number of story points. Weak teams will tell stories that magically add up to X. Writing a Hello World program will magically get an “8” and you add 8 more such story points, you already exceed X. Now you are looking awesome. Because mediocre team players are good at playing politics, everyone scratches everyone’s back. Dissenting voices will be frowned upon and soon those disenting will become demotivated and maybe more on. Everyone wins.

4. 5-6 is the ideal number for the team size
This one size fits all teams in a large project is not fair. Some team members work well and some don’t. Human dynamics and interactions are complex expecially when survival is at stake as is the case with mediocre team members. So for some teams, 3 may be the optimal size where as 6 may work better with another. Teams are supposed to be dynamic in constitution but that will work only if we have a bunch of top-notch folks

So, do you have the guts to do agile? I hope so. And, good luck.

Opening an iPhone 3G – Be Extra Careful

This post is not a tutorial on how to open an iPhone 3G. There are numerous good guides on the web and YouTube. If you are looking for a guide, I suggest the excellent iFixIt guides here. However, all the guides and videos I have come across use the first generation iPhone and not the 3G. This is strictly my opinion and is based on a sample size of 1. I am using my iPhone 3G as a reference. When I opened my iPhone I was surprised to find an extra connection, which, had I not been careful, could have easily ripped and damaged the device.

Installing and using the crappy AT&T Navigator busted the speaker on my iPhone. My iPhone is on permanent mute, vibrate only mode. Can’t hear a thing from the speakers. No phone rings, no marimba tune. I managed to find a repair store in Atlanta which wants to charge $100. It’s still cheaper than the other options and no, I did not get the AppleCare. I know, hindsight. However, the store has not returned my call since November. I found the replacement dock connecter+speaker assembly on for $19. Next step was to replace the broken part. Haven’t found time to do it yet, because, if I completely damage the phone I need time to run to the AT&T store and get the cheapest phone so I don’t miss any calls.

Here are the tools you will need to open the iPhone. Some guides suggest using a flat screwdriver to pry open the top, after removing the bottom screen.

iPhone Opening ToolsI do not recommend doing that, because the potential of you damaging the phone is very high. The cheap plastic suction cup can be found at any Home Depot or Lowes. Get the one shown in the picture. The hook comes in handy pulling the lid open and the suction is good enough. A thin gasket lines the glass cover of the iPhone and using a knife or any other tool to pry open the lid will damage the gasket. 

Also recommend keeping a magnet handy as the screws are tiny and you don’t to lose any. The magnet will come on handy if you drop any screw. Another tip, take pictures of each step so you can use it was a guide to help you put the device back together. Yet another tip, backup your iPhone before attempting to open it. Better safe than be sorry.

The picture on the right, borrowed from iFixIt.Com should the iPhone open. One thing to note is there is no connector connecting the top to the bottom like the one I found in my iPhone.




The picture on the left is the dock assembly. The connector shown is attached to the top of the iPhone where the arrow points to in the picture on the right. The very first time you try to open your iPhone 3G using the suction cup, you will find that a little extra pull is required. Don’t just yank the top. You will need a couple of tries before you can successfully dislodge the top, but knowing that there is connector will help you be extra careful.

Good luck.

How Android devices can leapfrog the iPhone

I love my iPhone and it’s a great platform for delivering all kinds of applications. Just like the ad says, there is an app for everything (at least it seems like that). The bottleneck, however, is the AppStore and Apple’s stranglehold on the device. You can’t just re-purpose the device without jail-breaking. The iPhone is versatile, yet, constrained. If you look at the numbers published here on GigaOM, you can see the extent of iPhone’s market and its economy. Android or any other device has a lot of catching up to do.

However, I think there is opportunity here for Android to completely blindside Apple and make Android devices indispensable. Google can do that, not by courting consumers, but by collaborating with makers of complex software systems like HMSes (Hospital Management Systems).

A hospital is a complex system and a truly integrated solution is mind-boggling. It takes a lot of brain power to comprehend the enormity of implementing such a project at even a mid-size hospital. There are processes within processes and to top that everything is highly regulated. It’s a question of life or death. Literally.

The typical architecture of HISes (Hospital Information Systems) is client-server, mostly implemented in Java. Large established hospitals still run mainframes but the basic architecture is client-server. The textbook approach of modernizing such “legacy” systems is to go the web applications route with a heavy mix of web-services to make everything “service-oriented”. You would probably throw in lots of JSP (Java Server Pages) pages and expect them to run in a browser. So the browser becomes your client accessing the application functionality. Then, you sprinkle the campus with desktops running browsers and you have your setup.

My proposal is this. Instead of using $500 desktop based browser clients to access system functionality why not access the functionality from $200 Android devices? Heck, with bulk orders, these could even cost about $100. These devices will access the required functionality via Android apps. Just imagine what would happen if Google and McKesson were to collaborate. McKesson’s Paragon Community HIS can dole out app features via Android apps. Google could subsidize these devices and could reduce the overall implementation cost of the system. Granted not all application features can be appified. (I invented this word, if anyone patents it, you heard it first here). But I suspect most of the features can be. So instead of nurses or hospital staff needing to go back to their stations to access the system, they can whip out their Android devices, and perform their tasks right at the point of the service. No need to make entries on paper charts and then transfer them into the system back at the station. Just tap them into the device. Throw in a pico-projector into the device and you have the option of viewing the data on a large screen. Like, say, you want to view the blood glucose chart of a patient or the vital signs charts. The possibilities are endless.

So instead of trying to create web clients or thin desktop clients, makers of complex software systems should focus their effort on developing downloadable android apps of their applications’ functionality. And McKesson, if you are looking for someone to lead up such an effort, you know where to find me.

Putting Microsoft Tag to meaningful use

I while back my colleague and I were discussing how far the bar code has come and how there are different kinds of bar codes and how a lot of information is being packed into those humble stripes. I had read that in Japan, advertisers put black and white matrix on posters and you can take a picture of the code using your mobile phone and get additional information or coupons for the service. People will figure our ingenious ways to put technology to good use.

I came to know the existence of Microsoft Tag via Glen Gordon. I downloaded Microsoft Tag Reader iPhone app and played with it a little. Toyed around with a few ideas and planned a project that could use it. Then I got busy at work. There is so much stuff to do at work that I find it hard to work on any of the personal projects.

This afternoon @lizasisler tweeted about Microsoft Tag and wondered how it could be used to better Health Care. We exchanged a couple of ideas.

@lizasisler: Saw @MicrosoftTag @ #WPC09 Neat printable interactive barcode technology Thoughts on good #Healthcare uses?

@rsringeri: @lizasisler @MicrosoftTag have med devices display MS Tags that can be snapped with mobile app to upload to @HealthVault.

@lizasisler: @rsringeri Nice! Think there could be great @MicrosoftTag uses in Healthcare – drug/equipment uses/education etc

@rsringeri: @lizasisler agree. Instead of the paper manual in the box, put a MS Tag on the device that takes you to the device’s home page on you iPhone

@lizasisler: @rsringeri What abt using @MicrosoftTag as emergency gateway to @HealthVault information. Click on tag interact with/access HealthVault?

@rsringeri: @lizasisler emgcy access is a great idea. My @HealthVault should have a section where I can put in non-stealable data, get a tag, ….

@rsringeri: @lizasisler … snap tag from mobile device and download vital emgcy data to Healthcare prof’s device. Blood Group, diabetic, allergies

Here are some ideas for meaningful use of Microsoft Tag in Health Care

  • Medical devices like BP and Blood Glucose meters can display, in addition to numbers, an MS Tag with the data encoded. I can then whip out my MS Tag reader app on my iPhone, snap a pic and upload the data to my Health Vault repository. No cables to fumble. No PC to connect the device to. Instead of trying to make the device Internet enabled, just modify the screen to display an MS Tag. And if I happen to use multiple devices to manage my health I don’t have to buy cables for each of these devices and connect them to a computer one after another. Most device manufacturers do not bundle a cable to connect the device to a computer.
  • Instead of including product manuals, instructions with med devices, just put couple of MS Tags on the device. Whip out the Tag reader app again, snap the pic and the iPhone can now play a video demo of the device or load a PDF manual, with click enables links.
  • Enable Health Vault to create an MS Tag that encapsulates data that I decide to make available to emergency medical personnel. I could carry a MS Tag card in my wallet (or a dog tag) that can be used by medical personnel to gather vitals stats like blood group, allergy information in situations where I may be unable to communicate that info.
  • The above idea can be expanded to create a portable medical record I can carry for my visit. Prior to my doc visit, I logon to Health Vault, select a bunch of data points, export that as an MS Tag, save the tag on my iPhone, and assign an expiration date to it. At the doc’s office, the doc or other Health care personnel can “read” the encoded information using a MS Tag Reader. I don’t have to print anything nor do I have to logon to a computer at the doc’s office to make the information available.
  • Put MS Tags on medication bottles. Snap pics of all the medications and an app can figure out and warn about potential drug interactions. Couple that with data from med devices and the app can alert you – hey your blood sugar is high pop this pill from your prescription

These are just a few ideas I dumped from my brain. What’s yours? With the availability of Microsoft Tag API here, I guess it’s only a matter of time before we see some implementations.


Check out Vizitag, their blog and follow them on Twitter. Interesting applications of Microsoft Tag and bar codes.