Creating Windows Mobile Databases with SQL Anywhere

The SQL Anywhere product is an entire suite of database applications and servers. It runs on many platforms, including Windows Mobile. Using Visual Studio, programmers can develop database applications that run on a Windows Mobile device.

One of the biggest problems I've run into when developing for mobile devices is data storage. Two problems come up. First, I'll often be synchronizing with a server using a SQL database. Second, I'll want to use relational databases in my mobile app itself while most devices today don't natively support SQL. (The Android platform is an exception here. It includes SQLite.)

About a year ago, I started exploring Sybase's SQL Anywhere product for another project that I was working on here at the office, and I was quite impressed. SQL Anywhere is actually a suite of tools, and included in it are several desktop versions, as well as a version that runs on Windows Mobile. Additionally, there's the Ultralite edition, which runs on smaller Windows CE devices and Palm OS, and the Ultralite J edition-the J is for Java-which runs on BlackBerry and J2SE (Java 2 Platform Standard Edition).

eWEEK Labs Walk-through: SQL Anywhere version 11

What's cool about the Windows Mobile edition is it allows developers to have full relational database access through SQL right on a mobile device running Windows Mobile. Users can store the tables right on the device, and later synchronize them with a server. For many of us, this is exactly what we need.

Sybase recently released version 11 of SQL Anywhere. For this article, I'm exploring the SQL Anywhere on a Windows Mobile 6 device (specifically an HTC/AT&T 8525 phone that has been upgraded to Windows Mobile 6).

Sybase Who?

About six months ago, I was talking to a friend of mine and I mentioned I was trying a product from Sybase. He was a bit surprised and said, "Sybase? They're still around?" Indeed they are. While they seem to have fallen behind in the database competition against such players as Oracle and Microsoft SQL Server, Sybase is definitely still a major player.

The product I'm looking at, SQL Anywhere, comes from a subsidiary of Sybase called iAnywhere. iAnywhere was formed in May 2000, and the company has produced a huge set of products.

The SQL Anywhere product includes a free Developer version that I'm using for this article.

Windows Version and Windows Mobile Edition

To use the Windows Mobile edition, developers actually install the whole Windows desktop version of SQL Anywhere. With that comes the Windows Mobile edition that is then installed on the Windows Mobile device.

The full Windows version includes a whole set of development tools, including a .NET assembly that runs on Windows Mobile. That way, programmers can develop using C# within the familiar Visual Studio environment.

A Few Minor Problems

I did have a few problems up front. I have Visual Studio 2008 installed on my computer, but the SQL Anywhere installer kept wanting to launch the 2005 version of Visual Studio to do some additional installation. Also, while I normally have the annoying Vista User Account Control turned off, I had momentarily turned it back on about a week ago and forgot to turn it back off. When Visual Studio launched, I kept getting messages that it should run with Administrator privileges. Since the SQL Anywhere installer launched Visual Studio, I had no control over that. (Also, the README file included with SQL Anywhere talked about how Visual Studio 2008 would be out later this year. Apparently this installer was created before 2008 was released. Sybase really should fix that now that 2008 has been out for awhile.)

The other problem I had was finding the documentation. The documentation is available, but it has to be downloaded separately, which requires you log into the company's Web site with a username and password. (Registration is free.) Although this isn't a huge deal, from the standpoint of software usability, I shouldn't be left with the installation program closing and me left wondering where to go next. So for those installing the software and looking for the documentation, look in the README that opens after installation, and scroll down to the part on Documentation. Ignore the mention that the documentation was installed (it wasn't, even though it said it would be), and copy the provided link into the Web browser. There will be a download that installs the documentation; from there, users should head over to the C:\Program Files\SQL Anywhere 11\Documentation\en\HTMLHelp and open the sqlanywhere_en11.chm file to get started. Once a programmer finally jumps through the hoops and gets there, they'll find several "Getting Started" documents.

Also, for the samples, I had to hunt a bit for them, too; they're in the folder C:\Users\Public\Documents\SQL Anywhere 11\Samples.

Getting SQL Anywhere onto my Windows Mobile device was a bit of a problem as well-again, not because of functionality problems, but simply finding out how it's done. I resolved this pretty quickly through the forums on the Sybase site. In the directory C:\Program Files\SQL Anywhere 11\CE\Deployment, there's a program called cedeploy.exe. (Again, I'm not trying to gripe too much here, but I shouldn't have to go searching like this. A Google search of "cedploy.exe" yields only seven pages, and none in the official documentation. Fortunately, this is a one-time thing, and these issues here were the only real problems I encountered.)

The actual installation on the device, however, went perfectly fine. The utility created a CAB file, which I copied over to the device. I then ran the CAB file, which installed the software smoothly without incident.

Building in Visual Studio

Creating an SQL Anywhere for Windows Mobile application in Visual Studio is quite easy if you're familiar with creating database applications. One sample that I started with is in the directory C:\Users\Public\Documents\SQL Anywhere 11\Samples\SQLAnywhere\CE\ado_net_sample.

This sample demonstrates the iAnywhere.Data.SQLAnywhere namespace, which includes several of the usual types of classes for .NET database development. For example, the namespace includes classes such as SAConnection, SADataAdapter, and SADataReader. If a programmer has done database development on .NET, they'll see the obvious analogy between these classes and the usual database classes.

Additionally, they can use data-bound controls such as the DataGrid control. In other words, there should be very little learning curve for develping for SQL Anywhere on a Windows Mobile device.