Programatically create SQL Server CE 2000 database in C#

Hello,

Can anyone point me to a way to programatically create a SQL Server CE 2000 database (.sdf file) using C#.

Cheers

Andrew
LVL 4
andrewharrisAsked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
Hi andrewharris,

SqlCeEngine engine = new SqlCeEngine("Data Source = C:\\test.sdf");
engine.CreateDatabase();

/*Connecting to a SQL CE database*/

SqlCeConnection ssceconn = new SqlCeConnection("Data Source = C:\\test.sdf");
ssceconn.Open();
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
0
 
andrewharrisAuthor Commented:
aneeshattingal my friend... you are a star! That worked a treat, just had to change C:\ to a valid Pocket PC path, ie \\Program Files\\TestApp\\, etc

And just to add for anyone else who looks for this, to password protect the database:

SqlCeEngine engine = new SqlCeEngine("Data Source='\\Program Files\\TestApp\\test.sdf'; Password='password'");
engine.CreateDatabase();

Cheers

Andrew
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
Ok.. Now you can close the Question ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.