Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / Windows Forms

SQL Server to SQL Server Compact Edition Database Copy Utility

Rate me:
Please Sign up or sign in to vote.
4.95/5 (39 votes)
26 Jun 2008BSD2 min read 344.5K   16.8K   123   59
Create and manage your mobile database using SQL Management Studio and export them to SQL Compact Edition databases
Image 1

UPDATE

Please download the latest version of this tool from JohnnyCantCode.com. 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".

Introduction

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.

Background

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 www.JohnnyCantCode.com. 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.

History

  • 1.0 Initial release

License

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


Written By
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.

Comments and Discussions

 
QuestionJohnny Can't Code? Pin
Member 78058094-Apr-11 5:43
Member 78058094-Apr-11 5:43 
Generalgetting error just-in-time (JIT) debugging instead of this dialog box Pin
psnlakshmi30-Oct-10 1:40
psnlakshmi30-Oct-10 1:40 
GeneralBad Image Format Exception Pin
i_lonsdale@hotmail.com15-Oct-10 22:43
i_lonsdale@hotmail.com15-Oct-10 22:43 
Generalproblem with varbinary Pin
pgarbo17-Aug-10 5:05
pgarbo17-Aug-10 5:05 
GeneralThanks Pin
Uros Calakovic8-Aug-10 2:00
Uros Calakovic8-Aug-10 2:00 
QuestionException where Copying Database Pin
EdgarVegaD14-Jan-10 4:36
EdgarVegaD14-Jan-10 4:36 
AnswerRe: Exception where Copying Database Pin
EdgarVegaD14-Jan-10 8:14
EdgarVegaD14-Jan-10 8:14 
AnswerRe: Exception where Copying Database Pin
dille421-May-10 3:34
dille421-May-10 3:34 
GeneralGETUTCDATE() & Multi-Column Key's Pin
michael@merlot.com21-Nov-09 4:41
michael@merlot.com21-Nov-09 4:41 
GeneralFor SQL Server CE 3.5 SP1 Pin
kshakir23-Jul-09 10:08
kshakir23-Jul-09 10:08 
For the other SQL Server CE 3.5 SP1 people, I was able to get it to work by modifying SelectMobileAssembliesDialog.cs line 98 to:

if (ver.FileMajorPart == 3 && ver.FileMinorPart == 5)


Also, I ran into some issue in the FinishCtrl.cs trying to update the progress bar based on the number of rows. As I was only using this for a POC, I didn't debug it (I think my data made it! Wink | ;) and instead hacked lines 58 & 59 to say:

progressBar1.Maximum = Math.Max( value, max );
progressBar1.Value = Math.Min( value, max );


Other than that it worked great! Thank you very, very much for developing this tool, and for releasing the source to the community.
QuestionSql 2008 support? Pin
khanricksteele29-Apr-09 7:26
khanricksteele29-Apr-09 7:26 
QuestionUnknown datatype Pin
amre3l18-Mar-09 23:38
amre3l18-Mar-09 23:38 
AnswerRe: Unknown datatype Pin
Francois YACOB16-Jun-09 6:32
Francois YACOB16-Jun-09 6:32 
GeneralPrimery Keys are not correct after import to SQL Compact Pin
voellinger26-Jan-09 0:51
voellinger26-Jan-09 0:51 
GeneralOut of memory error Pin
cess30-Nov-08 9:36
cess30-Nov-08 9:36 
Generalthere is problem with NVARCHAR(MAX) Pin
Tajniak520-Nov-08 5:51
Tajniak520-Nov-08 5:51 
Generaliv been messing with this for a while until i found this.TNX!!!!! Pin
zivzuv18-Nov-08 20:37
zivzuv18-Nov-08 20:37 
Generalprimary key contraint names Pin
mape108219-Aug-08 5:04
mape108219-Aug-08 5:04 
GeneralRe: primary key contraint names Pin
Francois YACOB16-Jun-09 6:38
Francois YACOB16-Jun-09 6:38 
GeneralThis thing rocks! Pin
granadaCoder5-Aug-08 10:32
granadaCoder5-Aug-08 10:32 
GeneralGreat work!!! only one thing and an Idea for future work Pin
mape108223-Jul-08 6:19
mape108223-Jul-08 6:19 
GeneralRe: Great work!!! only one thing and an Idea for future work Pin
Francois YACOB16-Jun-09 6:43
Francois YACOB16-Jun-09 6:43 
GeneralType Conversion errors Pin
gratajik15-Jul-08 13:25
gratajik15-Jul-08 13:25 
GeneralON DELETE ... ON UPDATE ... Pin
Hoang Cuong12-Jul-08 22:21
Hoang Cuong12-Jul-08 22:21 
Generaldata transfer Pin
Shaikh Sahrif28-Jun-08 19:18
Shaikh Sahrif28-Jun-08 19:18 

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.