3

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?

3 Answers 3

2

You will need at least the System.Data.SqlServerCe assembly. That is normally in the GAC but it might be usable as a locally copied DLL.

From there on you can instantiate a SqlCeEngine object and use CreateDatabase()

Here is some CodeProject example code in VB.NET.

Sign up to request clarification or add additional context in comments.

Comments

1

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)

Comments

-1

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
        }
    }
}

2 Comments

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.
Does what he put actually work? It isn't called SQL Server Everywhere any more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.