This project contains 4 command line applications:

- ExportSqlCE - for scripting an entire SQL Server Compact 3.5 database
- ExportSqlCE40 - for scripting an entire SQL Server Compact 3.1 database
- ExportSqlCE31 - for scripting an entire SQL Server Compact 3.1 database
and
- Export2SqlCE - for scripting an entire SQL Server 2005/2008 database providing SQL Compact compatible T-SQL statements.

Command line for ExportSqlCE, ExportSqlCE40 and ExportSqlCE31:

C:\Data\SQLCE\bin>exportsqlce
Usage :
  ExportSQLCE.exe [SQL Compact Connection String] [output file location] [exclude] [schemaonly|dataonly] [saveimages] [sqlazure]
Examples:
  ExportSQLCE.exe "Data Source=D:\Northwind.sdf;" Northwind.sql
  ExportSQLCE.exe "Data Source=D:\Northwind.sdf;" Northwind.sql exclude:Shippers,Products

Usage: (To create a schema diff script)
  ExportSQLCE.exe diff [SQL Compact or SQL Server Connection String (source)] [SQL Compact or SQL Server Connection String (target)] [output file location]
Example :
  ExportSQLCE.exe diff "Data Source=D:\Northwind.sdf;" "Data Source=.\SQLEXPRESS,Inital Catalog=Northwind" NorthwindDiff.sql

Usage: (To create a database graph)
  ExportSQLCE.exe dgml [SQL Compact or SQL Server Connection String (source)] [output file location]
Example:
  ExportSQLCE.exe dgml "Data Source=D:\Northwind.sdf;" C:\temp\northwind.dgml

Usage: (To create a Windows Phone DataContext)
  ExportSQLCE.exe wpdc [SQL Compact or SQL Server Connection String (source)] [output file location]
Example :
  ExportSQLCE.exe wpdc "Data Source=D:\Northwind.sdf;" C:\temp\Northwind.cs

Usage : (To script an entire database to SQLite format)
 ExportSQLCE.exe [SQL CE Connection String] [output file location] [sqlite]
Example:
 ExportSQLCE.exe "Data Source=D:\Northwind.sdf;" Northwind.sql sqlite


Command line for Export2SqlCE:

Usage :
 Export2SQLCE.exe [SQL Server Connection String] [output file location] [[exclude]] [[schemaonly]] [[sqlite]] [[saveimages]] [[preservedateanddatetime2]] [[keepschema]]
 (exclude, schemaonly, saveimages, keepschema and preservedateanddatetime2 are optional parameters)

Examples :
 Export2SQLCE.exe "Data Source=(local);Initial Catalog=Northwind;Integrated Security=True" Northwind.sql
 Export2SQLCE.exe "Data Source=(local);Initial Catalog=Northwind;Integrated Security=True" Northwind.sql schemaonly
 Export2SQLCE.exe "Data Source=(local);Initial Catalog=Northwind;Integrated Security=True" Northwind.sql exclude:dbo.Shippers,dbo.Suppliers
 Export2SQLCE.exe "Data Source=(local);Initial Catalog=Northwind;Integrated Security=True" Northwind.sql sqlite



Notice that the SQL Server Export currently does not support identically named tables in different schemas.

Command line utilities optional parameters:

exclude:
- list of tables to be excluded from scripting, separated by commas - sample: exclude:dbo.Shippers,dbo.Products

schemaonly:
- this will cause the script to not contain any data, by only table and constraint definitions - so no INSERT statments in the script.

dataonly:
- this will cause the script to contain INSERT statments only.

saveimages
- this will cause all image field data to be written to individual files rather than be included in the script. The files are named <NewGuid()>.blob, and are in the same folder as the generated script. The resulting script and related files can used by SqlCeCmd to import into a SQL Compact database file. This can be useful if your database contains large image fields (5-10 MB or more), in order to avoid out of memory errors.

sqlazure
- this will cause primary keys to be scripted before any INSERT statements, batch INSERTS in a GO per 1000 statements, and removes support for ROWGUIDCOL (which is not available in SQL Azure)

diff
- this will generate a SQL Schema Diff script based on differences between source and target data sources.

dgml
- this will generate a .dgml file and releated .sqlce/.sql files in the specified folder, that contains a diagram of the data source.

wpdc
- this will generate a .cs or .vb file with a Windows Phone specific Linq to SQL DataContext and related classes. Requires the Windows SDK version 7 to be installed.

sqlite
- this will generate a .sql script in SQLite3 dump file format, for more information see my blog post here

preservedateanddatetime2
- if this switch is not set (the default), Server columns of type "date" and "datetime2" are converted to datetime columns (which could cause data loss). If the switch is set, the columns are converted to nvarchar(10) and nvarchar(27), preventing any data loss.

keepschema
- this will create table names like "dbo.Shippers" instead of just "Shippers"

Last edited Sep 29 at 9:32 AM by ErikEJ, version 19

Comments

sandroriz Jul 2, 2012 at 2:47 PM 
Hi Erik,
I use very often you export2SqlCE tool.

Normally I'm using 3.5.2.0, today I downloaded last version (3.5.2.15) and on the same DB it gives me an exception and doesn't create the script

Error: System.ArgumentException: A relation already exists for these child colum
ns.
at System.Data.DataRelationCollection.DataSetRelationCollection.AddCore(DataR
elation relation)
at System.Data.DataRelationCollection.Add(DataRelation relation)
at System.Data.DataRelationCollection.Add(String name, DataColumn[] parentCol
umns, DataColumn[] childColumns)
at ErikEJ.SqlCeScripting.Generator.FillSchemaDataSet(List`1 tables)
at ErikEJ.SqlCeScripting.Generator.ExcludeTables(IList`1 tablesToExclude)
at ExportSqlCE.Program.Main(String[] args)

3.5.2.0 (fortunaltely I kept a backup) works perfectly.

thx

cosmmin_m Mar 16, 2012 at 7:59 AM 
Hi.
Tried to run the Export2SqlCE.exe with the [dataonly] switch but the generated file contains the table definitions as well. The [schemaonly] switch works fine. Any idea what might cause this issue? Using SQL Server 2008.
Thanks.

ner0 Jan 24, 2012 at 10:52 AM 
My bad... I was running the wrong tool... I guess I need a bit more sleep.
Anyone having problems might need SQL Server Compact 3.5 SP2 or whatever version you're using.
Tool works great!

ner0 Jan 24, 2012 at 10:08 AM 
When running the executable from the same folder it gets a different problem:
Message : A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source : .Net SqlClient Data Provider
Number : 53

What is this? Whis is it even talking about SQL server since the destination is an sql script file?
Anyway my SQL Server has remote TCP/IP and Named Pipes enables... How is this supposed to work?

ner0 Jan 24, 2012 at 9:58 AM 
The same thing happens to me, when using the following connection string:
Export2SqlCE.exe "Data Source=c:\sqlce\mydb.sdf" mydb.sql

Gives me error message:
Message : A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Source : .Net SqlClient Data Provider
Number : -1

ErikEJ Oct 15, 2010 at 6:33 AM 
Export2sqlce requires a SQL Server connection string, to export a SQL Server Compact file, use the exportsqlce utility.

hardywang Oct 15, 2010 at 12:42 AM 
I run Export2SqlCE.exe "Data Source=d:\temp\abc.sdf;" abc.sql and got error messafe

Message : A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Source : .Net SqlClient Data Provider
Number : -1

Any idea? The file path is correct.