Skip to content
TheCodeKing edited this page Jul 16, 2011 · 4 revisions

Overview

SqlHarvester is a free command-line based scripting engine written in .Net. It enables the import/export of database content across disconnected Sql Server databases.

Features

  • Compatible with Sql Server 2000/2005/2008
  • Update/insert of data based on primary keys
  • Runtime enable/disable of constraints
  • Handles unicode & binary data types
  • Script subset of data from multiple tables
  • Transaction based data import
  • Command-line based interface, integrates with build scripts

Usage

The SqlHarvester takes parameters from the command line. Any arguments not passed on the command line are read from the SqlHarvester.exe.config file. This allows persistent settings such as configuration connection strings to be defined once.

SqlHarvester [-export|-import] [<option>]
    -export    
              Exports content from the target database.
    -import   
              Imports content into the target database.
Options:
    -connectionString:<connectionString>
              The connection-string used to connect to the target database.
    -tables[:tableExpression1,[:tableExpression2], ...]
              Defines one or more tables from which to script content.
    -defaultScriptMode:[NotSet|Delete|NoDelete]
              Specifies if content is scripted with deletes by default.
    -outputDirectory:<filePath>
              The location of script files for scripting or seeding.
   -verbose:<level>
              Specifies the output verbose level (0-4). 

Table expression syntax:
     "<tableName> [Where <condition>] [With NoDelete|Delete]"

Examples

The following scripts content from the table TableA where it meets the condition TableId>10. Any existing content not matching this criteria in the target database will be deleted when the script is imported.

SqlHarvester -export -tables:"TableA Where TableId>10 With Delete"

The following scripts content from table TableA where it meets the condition TableId>10. When imported the scripted content will be merged with any existing content. Existing rows will be updated, missing rows will be inserted.

SqlHarvester -export -tables:"TableA Where TableId>10 With NoDelete"

The following scripts content from the table TableA, TableB and TableC. Each table has a different delete mode and filter specified. The verbose mode is set to 3.

SqlHarvester -export -tables:"TableA With NoDelete":"TableB":"TableC Where ColumnB='A' With NoDelete" -verbose:3

The following scripts content from all user-database-tables. The * wildcard may also be used when defining tables in the configuration file.

SqlHarvester -export -tables:"*"

The following imports pre-scripted content from the output directory into the Demo database. Data is imported within a transaction and rolls back on error. Database constraints are disabled during the import process.

SqlHarvester -import -connectionString:"data source=(local);Integrated Security=SSPI;Initial Catalog=Demo"

The following imports pre-scripted content from the specified directory SqlScripts, into the default target database defined in the configuration file. Any files with the Sql extension within this directory will be imported.

SqlHarvester -import -outputDirectory:"C:\SqlScripts"
Clone this wiki locally