views:

902

answers:

2

In an ASP.NET web application I have to dynamically create a SQL Compact 3.5 database for a Windows Mobile Compact Framework application from a data source (SQL Server).

I have to create the database file, needed objects (tables, ...) and fill the tables with data. The client application (Windows Mobile device ) will download that generated file.

What prerequisites (referenced assemblies, installations) do I need - or: is this even possible?

+1  A: 

Essentially Henk's answer points in the right direction. But there are some caveats. The SQLServerCE assembly throws runtime errors.

I found these two helpful links:

In order to use the assembly, you have to call this method:

AppDomain.CurrentDomain.SetData("SQLServerEverywhereUnderWebHosting", true)
splattne
A: 

You need the SQL Compact 3.5 SP1 Runtime:

http://www.microsoft.com/downloads/details.aspx?FamilyId=DC614AEE-7E1C-4881-9C32-3A6CE53384D9&displaylang=en

Then add a reference to System.Data.SqlServerCe

Here is some sample code that creates a new database:

using System.Data.SqlServerCe;

public static class SqlCompactServices
{
    public static void CreateDatabase()
    {
     string connectionString = "Data Source=file.sdf";
     using (SqlCeEngine engine = new SqlCeEngine(connectionString))
     {
      engine.CreateDatabase();
     }

     using (SqlCeConnection connection = new SqlCeConnection(connectionString))
     {
      connection.Open();
      // preform queries just like "regular" SQL Server
     }
    }
}
Bryan
Did you even bother to read splattne's answer? THe point is that you have to call a special method to get it to work.
ctacke
Does what he put actually work? It isn't called SQL Server Everywhere any more.
Bryan