1

I'm having a go at learning to use SQL Server CE databases as a storage medium for my applications. I've currently been storing data in text and xml files, but thought I should move onto something more appropriate for my project as the text files are getting abit messy.

I have now learnt how to programmatically create an SQL Server CE 4.0 database file in C#, but is there any way to programmatically add an already built Schema to that newly created database file in C#?

2
  • @Guvante yes you're right, I will delete my comment. Commented Feb 23, 2013 at 19:33
  • 1
    That question is not a duplicate, this one asks for schema and doesn't even reference dynamic creation of the final file. (Re-added comment for others) Commented Feb 23, 2013 at 19:35

1 Answer 1

1

I guess, it depends on what approach you use to work with a database. If Linq to Sql is available (say, you're not using .Net Compact Framework), you can create database by the following code:

using (MyDataContext dc = new MyDataContext("Data Source=\"test.sdf\""))
{
    dc.CreateDatabase();
}

instead of

SqlCeEngine en = new SqlCeEngine("Data Source=\"test.sdf\"");
en.CreateDatabase();

Linq DataContext creates db schema automatically.

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

Comments

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.