-
-
Notifications
You must be signed in to change notification settings - Fork 175
Command line tools
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
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
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
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 https://erikej.blogspot.com/2012/08/exporting-sql-server-compact-to-sqlite.html
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"