Skip to content

Command line tools

Erik Ejlskov Jensen edited this page Aug 17, 2018 · 12 revisions

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 4.0 database
  • ExportSqlCE31 - for scripting an entire SQL Server Compact 3.1 database and
  • Export2SqlCE - for scripting an entire SQL Server 2008 and later database providing SQL Compact/SQLite compatible T-SQL statements.

The latest version of the command line tools are available here: https://github.com/ErikEJ/SqlCeToolbox/releases

Command line samples for ExportSqlCE, ExportSqlCE40 and ExportSqlCE31

To generate a SQL script from the database file

ExportSQLCE.exe [SQL Compact Connection String] [output file location] [exclude] [schemaonly|dataonly] [saveimages] [sqlazure]

    ExportSQLCE.exe "Data Source=D:\Northwind.sdf;" Northwind.sql
    ExportSQLCE.exe "Data Source=D:\Northwind.sdf;" Northwind.sql exclude:Shippers,Products

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]

  ExportSQLCE.exe diff "Data Source=D:\Northwind.sdf;" "Data Source=.\SQLEXPRESS,Inital Catalog=Northwind" NorthwindDiff.sql

To create a database graph

ExportSQLCE.exe dgml [SQL Compact or SQL Server Connection String (source)] [output file location]

  ExportSQLCE.exe dgml "Data Source=D:\Northwind.sdf;" C:\temp\northwind.dgml

To create a Windows Phone DataContext

ExportSQLCE.exe wpdc [SQL Compact or SQL Server Connection String (source)] [output file location]

 ExportSQLCE.exe wpdc "Data Source=D:\Northwind.sdf;" C:\temp\Northwind.cs

To script an entire database to SQLite format

ExportSQLCE.exe [SQL CE Connection String] [output file location] [sqlite]

 ExportSQLCE.exe "Data Source=D:\Northwind.sdf;" Northwind.sql sqlite

Command line for Export2SqlCE

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

 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

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

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"