Click here to Skip to main content
15,889,849 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 348.7K   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

 
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 
GeneralBrilliant Pin
Johnny J.26-Jun-08 20:44
professionalJohnny J.26-Jun-08 20:44 
Absolutely brilliant tool. You can edit SQL Server CE databases directly using the Management Studio, but it's a poor interface to say the least. And there's a lot of things you can't do that you can normally do with SQL Server databases. Just renaming a field in a table is more work than it should be.

This tool is a big help. Now you can manage your compact database in SQL Server and generate the database from that... Great!

What I would like to see next is the ability to synchronize data from your compact database back to the sql server, because let's say you design the database in SQL Server, perhaps fill it with some data. The you export everything to a compact database and run your application that adds further data to the database. Then at some time, you need to change the layout of the database (which of course you want to do in SQL Server Management Studio), but you don't want to lose the data that has been added to the compact database in the mean time... You get my point, I'm sure...

You've got my 5 for this! HOWEVER - I don't like the name of your site... Poke tongue | ;-P

/Johnny J.

PS: A small but useful feature would be if the program could automatically scan the system for the needed dll's.
GeneralError after conversion.. Opening converted file with SQL Management Studio Pin
Allan Chong5-Jun-08 17:46
Allan Chong5-Jun-08 17:46 
GeneralRe: Error after conversion.. Opening converted file with SQL Management Studio Pin
johnnycantcode12-Jun-08 9:34
johnnycantcode12-Jun-08 9:34 
GeneralNot working with SQL2000 Pin
oldieman2-Jun-08 22:28
oldieman2-Jun-08 22:28 
GeneralVisual Studio Pin
gnassar2-Jun-08 2:26
gnassar2-Jun-08 2:26 
GeneralRe: Visual Studio Pin
johnnycantcode12-Jun-08 9:35
johnnycantcode12-Jun-08 9:35 
GeneralSchema Setting + SqlCe Version Pin
Charl Victor12-May-08 23:27
Charl Victor12-May-08 23:27 
GeneralRe: Schema Setting + SqlCe Version Pin
johnnycantcode13-May-08 3:22
johnnycantcode13-May-08 3:22 
AnswerRe: Schema Setting + SqlCe Version Pin
Charl Victor14-May-08 5:17
Charl Victor14-May-08 5:17 
GeneralTriggers and SP Pin
CDFaux7-May-08 3:13
CDFaux7-May-08 3:13 
GeneralRe: Triggers and SP Pin
johnnycantcode8-May-08 2:31
johnnycantcode8-May-08 2:31 
GeneralRe: Triggers and SP Pin
CDFaux8-May-08 10:24
CDFaux8-May-08 10:24 
GeneralRe: Triggers and SP Pin
Charles K. Kincaid23-Jun-09 7:58
Charles K. Kincaid23-Jun-09 7:58 

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.