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]] [[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
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
herepreservedateanddatetime2- 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"