0

I would like to use the SqlCeEngine class to build a database and populate it with tables (like this question) but using a script generated by ExportSqlCE.

I was wondering if this was possible using SqlBulkCopy? (A SQL Server CE version which has been replicated here).

Or if there is another solution to quickly populating a .sdf database file with tables and constraints (28 tables, 52 constraints, most columns cannot be null).

When my application loads I check to see if the database file exists. In the eventuality that this file is missing (or when the program is loaded for the first time after installation) I want to be able to re-generate an empty database.

I created the database using DataPort Console because as its my first real database application I wanted to design the database graphically.

6
  • Why not simply include an empty database file with your application, and copy it to the desired location if required? Commented Mar 12, 2013 at 17:17
  • In the event the Database file is lost I want the the application to be able to maintain itself. Commented Mar 13, 2013 at 8:20
  • Yes, my proposal will allow you to do that... Commented Mar 13, 2013 at 9:10
  • This does not solve my issue as later I want to have the option of altering the database. I want to have the ability to give the user an updated version of the application that may need to re-build the database. I would like the option of extracting their data, deleting the database, rebuilding with a new schema and then importing their data under the guise of "Program Initialization After Installation" so that they cannot see changes. I'd rather not have to provide a new Database (even if its empty) whenever I change things Commented Mar 13, 2013 at 10:04
  • OK, now you explain your requirements! - You should provide ALTER TABLE/CREATE TABLE scripts with the updated app, and maybe store the current database version in a database table. Commented Mar 13, 2013 at 11:13

1 Answer 1

1

Ultimately I was not able to find a solution that replicated my desired functionality and instead, following the advice of ErikEJ decided to implement a series of scripts to be run on load. The ExportSqlCE is still useful for creating scripts of an already defined SQL Server CE database.

I eventually implemented a List<string> in which I added the various scripts. This allows me the option of loading scripts if I want to update a Database or choosing hardcoded "default" scripts for the initial version of a database. I could then loop around the List elements changing the SqlCeCommand command.CommandText property to the next element in the List.

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.