Question

I'm doing a project with vb.net (smart device) on visual studio 2008 and I need to connect to a database on the device itself (I do not have a physical device to test, only emulation). How should I go about doing it? I would like the database to be in the device on start up.

I've read on the internet that you have to make a reference to System.Data.SqlServerCe but the documents are, in my opinion, vague. So, I'm pretty lost here.

Was it helpful?

Solution

So there are two questions here:

  1. How do I deploy my database so it's there when my app starts?
  2. How do I access that database from my app?

Both are straightforward.

A1. You have a couple options. First, understand that SQLCE databases are a single file, typically with an SDF extension. You can either package it with your app for deployment, so you know it will be there on first run, or your app can check for its existence on startup and crete the file if it's not there. If you need to populate the initial database with data (lookups, etc) then option 1 is probably better. As long as you deploy/crete the database in a persistent storage location (and under WinMo/Pocket PC that's pretty much anywhere), it will always be there when your app starts up.

A2 You are correct that you need to add a reference to System.Data.SqlServerCe, which is again straightforward. Just add a reference in your smart device project:

enter image description here

Once you've done that, you use the SqlServerCe namespace objects to create the database, tables, indexes, etc, insert and query data, and all of that good stuff. Tutorials 2 and 3 on MSDN here are a really good start and they have VB.NET examples. The nice thing is that most desktop examples for VB.NET accessing a SQLCE database will work as-is on the device, and the things that don't work are usually in the presentation of the data, not the actual database access code itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top