Click here to Skip to main content
11,920,641 members (57,448 online)
Click here to Skip to main content
Add your own
alternative version


123 bookmarked

SQL Server to SQL Server Compact Edition Database Copy Utility

, 26 Jun 2008 BSD
Rate this:
Please Sign up or sign in to vote.
Create and manage your mobile database using SQL Management Studio and export them to SQL Compact Edition databases


Please download the latest version of this tool from I have updated this utility based on some feedback from users.

I added the ability to select the schema you wish to copy. For most databases, this will simply be "dbo".

I fixed a bug where the application did not recognize a valid version of "System.Data.SqlServerCe.dll".


This utility will copy the schema and data from a normal SQL Server 2000/2005 database and export it to a SQL Server Compact Edition database. The tool supports version 3.1 or 3.5 of SQL Server Compact Edition.


I was working on a mobile application and needed an easy way to manage the table relationships and indexes without having to resort to scripting. I was familiar with using SQL Server Management Studio so I decided that I would write a utility that converted a normal SQL Server database to a mobile database. This way, I could continue using the tool I normally use to create and maintain my databases.

Using the Code

Feel free to take a look at the code and offer your most gracious comments. The application uses a wizard to walk you through converting a database. I have also included a normal WINFORM that also does the conversion, but I stopped development on this in lieu of the wizard, so the form is incomplete. I will be maintaining this code and writing more about it on my blog at You can find the original post here.

Points of Interest

This utility will copy Indexes, Primary Keys, Foreign Keys, Table structure and data. SQL Server Compact Edition does not have support for Views, Triggers nor Stored Procedures, therefore this utility does not copy these.


  • 1.0 Initial release


This article, along with any associated source code and files, is licensed under The BSD License


About the Author

Software Developer (Senior) Gologic Tech LLC.
United States United States
I work as an independent software architect and senior developer. I have worked on many large enterprise projects as well as small single user applications.

You may also be interested in...

Comments and Discussions

QuestionIndex was outside the bounds of the array. Pin
ari o130-Jun-15 23:46
memberari o130-Jun-15 23:46 
QuestionImport or Convert a mdf file to sdf Pin
HassanFad29-Jan-15 1:30
memberHassanFad29-Jan-15 1:30 
Question.Exe Pin
Member 1028672113-May-14 3:09
memberMember 1028672113-May-14 3:09 
SuggestionNVarCharMAX support Pin
Massood Khaari6-Nov-13 0:23
professionalMassood Khaari6-Nov-13 0:23 
Questionprovide .exe file for this project also Pin
Member 942577126-Jul-13 9:11
memberMember 942577126-Jul-13 9:11 
GeneralGreat tool - after some manual changes :-) Pin
dolbysys18-Feb-13 22:16
memberdolbysys18-Feb-13 22:16 
GeneralRe: Great tool - after some manual changes :-) Pin
pmiossec27-Feb-13 13:45
memberpmiossec27-Feb-13 13:45 
GeneralRe: Great tool - after some manual changes :-) Pin
ronan_mc25-Apr-13 14:07
memberronan_mc25-Apr-13 14:07 
GeneralRe: Great tool - after some manual changes :-) Pin
pmiossec28-Apr-13 2:43
memberpmiossec28-Apr-13 2:43 
Questiongeht nicht! Pin
Member 250914025-Jan-13 5:56
memberMember 250914025-Jan-13 5:56 
AnswerRe: geht nicht! Pin
dolbysys18-Feb-13 22:20
memberdolbysys18-Feb-13 22:20 
QuestionMdf----_> sdf and sdf ----> mdf Pin
cjgallardo9629-Oct-12 4:03
membercjgallardo9629-Oct-12 4:03 
Questionasm.GetType("System.Data.SqlServerCe.SqlCeEngine"); returns null Pin
bradut15-Oct-12 12:25
memberbradut15-Oct-12 12:25 
AnswerRe: asm.GetType("System.Data.SqlServerCe.SqlCeEngine"); returns null Pin
Jeff Wharton2-Jan-13 19:01
memberJeff Wharton2-Jan-13 19:01 
QuestionMy vote of 5 Pin
SPI24-Aug-12 8:20
memberSPI24-Aug-12 8:20 
GeneralMy vote of 5 Pin
Big D27-Apr-12 10:40
memberBig D27-Apr-12 10:40 
GeneralMy vote of 5 Pin
manoj kumar choubey17-Apr-12 3:21
membermanoj kumar choubey17-Apr-12 3:21 
GeneralMy vote of 5 Pin
footnote9-Sep-11 9:28
memberfootnote9-Sep-11 9:28 
QuestionIs there anyone able to make it work with SQL Server 2008 R2? Pin
Ehsan.thabit21-Jun-11 9:14
memberEhsan.thabit21-Jun-11 9:14 
GeneralSupport for Compact edition v3.5 sp2 Pin
jcgk_7713-Apr-11 3:32
memberjcgk_7713-Apr-11 3:32 
GeneralRe: Support for Compact edition v3.5 sp2 Pin
Member 849633121-Mar-12 10:40
memberMember 849633121-Mar-12 10:40 
QuestionJohnny Can't Code? Pin
Member 78058094-Apr-11 6:43
memberMember 78058094-Apr-11 6:43 
Generalgetting error just-in-time (JIT) debugging instead of this dialog box Pin
psnlakshmi30-Oct-10 2:40
memberpsnlakshmi30-Oct-10 2:40 
GeneralBad Image Format Exception Pin
i_lonsdale@hotmail.com15-Oct-10 23:43
memberi_lonsdale@hotmail.com15-Oct-10 23:43 
Generalproblem with varbinary Pin
pgarbo17-Aug-10 6:05
memberpgarbo17-Aug-10 6:05 
GeneralThanks Pin
Uros Calakovic8-Aug-10 3:00
memberUros Calakovic8-Aug-10 3:00 
QuestionException where Copying Database Pin
EdgarVegaD14-Jan-10 5:36
memberEdgarVegaD14-Jan-10 5:36 
AnswerRe: Exception where Copying Database Pin
EdgarVegaD14-Jan-10 9:14
memberEdgarVegaD14-Jan-10 9:14 
AnswerRe: Exception where Copying Database Pin
dille421-May-10 4:34
memberdille421-May-10 4:34 
GeneralGETUTCDATE() & Multi-Column Key's Pin
michael@merlot.com21-Nov-09 5:41
membermichael@merlot.com21-Nov-09 5:41 
GeneralFor SQL Server CE 3.5 SP1 Pin
kshakir23-Jul-09 11:08
memberkshakir23-Jul-09 11:08 
QuestionSql 2008 support? Pin
khanricksteele29-Apr-09 8:26
memberkhanricksteele29-Apr-09 8:26 
QuestionUnknown datatype Pin
Member 187125319-Mar-09 0:38
memberMember 187125319-Mar-09 0:38 
AnswerRe: Unknown datatype Pin
Member 265157316-Jun-09 7:32
memberMember 265157316-Jun-09 7:32 
GeneralPrimery Keys are not correct after import to SQL Compact Pin
voellinger26-Jan-09 1:51
membervoellinger26-Jan-09 1:51 
GeneralOut of memory error Pin
cess30-Nov-08 10:36
membercess30-Nov-08 10:36 
I am trying to copy a 2 GB file to SQL server Compact. The program keeps on reporting an "Out of Memory" exception. There is one large field (ntext type) The file was originally an access database with a memo field that was converted to SQL server express 2008. Program seems to work well except for this problem. Any suggestions would be appreciated.
Generalthere is problem with NVARCHAR(MAX) Pin
Tajniak520-Nov-08 6:51
memberTajniak520-Nov-08 6:51 
Generaliv been messing with this for a while until i found this.TNX!!!!! Pin
zivzuv18-Nov-08 21:37
memberzivzuv18-Nov-08 21:37 
GeneralGreat work!!! only one thing and an Idea for future work Pin
mape108223-Jul-08 7:19
membermape108223-Jul-08 7:19 
GeneralRe: Great work!!! only one thing and an Idea for future work Pin
Francois YACOB16-Jun-09 7:43
memberFrancois YACOB16-Jun-09 7:43 
GeneralType Conversion errors Pin
gratajik15-Jul-08 14:25
membergratajik15-Jul-08 14:25 
GeneralON DELETE ... ON UPDATE ... Pin
Hoang Cuong12-Jul-08 23:21
memberHoang Cuong12-Jul-08 23:21 
Generaldata transfer Pin
Shaikh Sahrif28-Jun-08 20:18
memberShaikh Sahrif28-Jun-08 20:18 
GeneralBrilliant Pin
Johnny J.26-Jun-08 21:44
memberJohnny J.26-Jun-08 21:44 
GeneralError after conversion.. Opening converted file with SQL Management Studio Pin
mGxAlander5-Jun-08 18:46
membermGxAlander5-Jun-08 18:46 
GeneralRe: Error after conversion.. Opening converted file with SQL Management Studio Pin
johnnycantcode12-Jun-08 10:34
memberjohnnycantcode12-Jun-08 10:34 
GeneralNot working with SQL2000 Pin
oldieman2-Jun-08 23:28
memberoldieman2-Jun-08 23:28 
GeneralVisual Studio Pin
gnassar2-Jun-08 3:26
membergnassar2-Jun-08 3:26 
GeneralRe: Visual Studio Pin
johnnycantcode12-Jun-08 10:35
memberjohnnycantcode12-Jun-08 10:35 
GeneralSchema Setting + SqlCe Version Pin
Charl Victor13-May-08 0:27
memberCharl Victor13-May-08 0:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151120.1 | Last Updated 26 Jun 2008
Article Copyright 2008 by johnnycantcode
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid