Feb 02

Local databases have been of much interest in Silverlight and when Windows Phone 7 released everyone asked where’s the local database ? Most developers on Apple iOS and Android devices are used to having local database support.. Even HTML 5 web browsers are getting them these days (except for Microsoft which hasn’t announced support for new WebSQL standards.. W3C has stopped work on this standard because quoting the W3C documents:

“The specification reached an impasse: all interested implementers have used the same SQL backend (Sqlite), but we need multiple independent implementations to proceed along a standardization path.”

The Cloud is one thing, but there needs to be a better support for localized data in apps so that apps can cache data and work faster in asynchronous applications, which most mobile and web applications are today..

So why isn’t there more support in Silverlight through the current version 4.0 ?

image

Well right away the SQLite supportive .Net folks folks over at PHX Software  tried to support Silverlight.. But had problems because it wasn’t written in managed code/C# so therefore wasn’t ready to go..

Quoting a response from Jeffrey A Becker on this thread:

“Basically it all boils down to "Silverlight doesn't support P/Invoke".  SQLite is an unmanaged dll which is merge-bin'd into the System.Data.SQLite assembly during build time.  Also I don't think Silverlight has any of the required bits of System.Data to make an ADO.Net provider work. AIR supports SQLite by directly embedding the SQLite dll into the AIR runtime”

Next something wonderful happened for the .NET community..

image

Noah Hart  ported SQLite to C#  and .NET.. This port was very accepted in the community

image

Next  over at Tim Anderson’s blog (Editor’s Note: if you aren’t reading this you should be)  Tim Anderson did a proof of concept port to Silverlight and wow it works (sort of )..

 

image

This was definitely not a production capable port but it did show a lot of promise that we could get here with this someday.. To make it work Tim had to remove all the locking, and adapt the file I/O to use isolated storage.

According to Tim’s article he mentions:

“As far as I can tell, Silverlight’s Isolated Storage does not support locking at all. If the same application were opened twice, for example in different browsers, that could cause problems, but in normal use it would likely be OK. “ The release mode executable was only 257KB so it’s size was very usable.

Tim’s proof of concept code can be found here..

Windows Phone 7 Version

Silverlight for Windows Phone 7 with full trust apps and local storage has a bit of a different story, though p/invoke and native code isn’t available.

imageThere is another port out there for Windows Phone 7  and isolated storage out there if you want to try it out.. 

ttp://sviluppomobile.blogspot.com/2010/03/sqlite-for-wp-7-series-proof-of-concept.html

The updated code now includes transaction support with the transaction-commit-rollback mechanism.

http://sviluppomobile.blogspot.com/2010/07/wp7-sqliteclient-with-transaction.html

 

SL5

 

So when Silverlight 5 was announced ,we found out on Scott Gu’s Blog that p/invoke would see a supportable SQLite version due to p/invoke support and full trust...

“Out of Browser: Silverlight 5 builds on the out-of-browser capabilities we introduced with Silverlight 5.  Out of browser applications can now create and manage child windows.  Trusted out of browser applications can now also use P/Invoke capabilities to call unmanaged libraries and Win32 APIs.  Enhanced group policy support enables enterprises to both lock down and open up security sandbox capabilities of Silverlight 5 applications.”

More hope was present. I would love to see this capability extended  and supported insdie both Silverlight 5 and in some way for Windows Phone 7 as well.. Would love to see regular Silverlight able to use SQLite in a full port.

If the W3C is suggesting it what would it hurt to add this to Silverlight or at least make it supportable. I love the idea of SQL Server compact here too but I’d much prefer at least in a local storage paradigm to see SQLite here.. This would show real openness and transparency and support aligned to an HTML5  / Silverlight cooperative future in my humble opinion.