Skip to main content
Version: 1.1 (Latest)

SQL Server

The FastWrappers-TSQL project wraps FastTransfer (and FastBCP) in a CLR Assembly, allowing you to call them directly from T-SQL using extended stored procedures. This enables seamless data transfer operations without leaving your SQL Server environment.

Extension Overview​

ItemValue
Repositoryaetperf/FastWrappers-TSQL
Latest versionv0.7.0
PlatformsWindows and Linux
CompatibilitySQL Server 2016+
info

This wrapper includes both FastTransfer (for database-to-database transfers and file imports) and FastBCP (for database-to-file exports). This documentation focuses on the FastTransfer functionality.

Features​

  • Native SQL Server IntegrationExecute FastTransfer commands directly from T-SQL
  • Secure Password ManagementBuilt-in AES-256 encryption for sensitive credentials
  • CLR Assembly IntegrationRuns as extended stored procedures
  • Detailed Result ReturnGet transfer statistics and performance metrics as SQL results
  • Flexible ConfigurationSupport for all FastTransfer parameters and connection types
  • Role-Based SecurityPredefined database roles for access control

Prerequisites​

Important

The SQL Server service account must have read/execute permissions on the FastTransfer directory and binaries.

Installation​

Download the latest release from the Releases page. Choose the installation method based on your SQL Server version:

FastWrappers-TSQL.bakSQL Server 2019+

  • FormatSQL Server Backup file
  • InstallRestore using SSMS
  • After installRequires manual CLR activation and trusted assembly configuration after restore
  • DownloadFastWrappers-TSQL.bak
FastWrappers-TSQL.sqlSQL Server 2016+

  • FormatPure SQL Script
  • InstallExecute using sqlcmd or SSMS
  • After installNothing: complete installation in a single script
  • DownloadFastWrappers-TSQL.sql

Post-Installation Configuration​

info

This section only applies to the .bak installation method. The .sql script includes all necessary configuration steps automatically.

After restoring the database, you must configure CLR integration. Two options are available:

This approach is more secure as it keeps TRUSTWORTHY OFF and doesn't require changing the database owner:

-- Enable CLR integration
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
GO

EXEC sp_configure 'clr enabled', 1;
RECONFIGURE;
GO

-- Extract the assembly hash and add it to trusted assemblies
DECLARE @hash VARBINARY(64);

SELECT @hash = HASHBYTES('SHA2_512', content)
FROM sys.assembly_files
WHERE assembly_id = (
SELECT assembly_id
FROM sys.assemblies
WHERE name = 'FastWrappers_TSQL'
);

EXEC sys.sp_add_trusted_assembly
@hash = @hash,
@description = N'FastWrappers_TSQL Assembly v0.7.0';
GO

Advantages:

  • TRUSTWORTHY remains OFF (more secure)
  • No need to change database owner
  • Only this specific assembly is trusted
tip

The assembly hash changes with each version. When upgrading, remove the old hash first:

EXEC sys.sp_drop_trusted_assembly @hash = <old_hash>;

Security Roles​

FastTransfer_Executor​

The FastWrappers-TSQL database includes a predefined database role that grants EXECUTE permission on the xp_RunFastTransfer_secure stored procedure.

-- Add a user to the role
ALTER ROLE [FastTransfer_Executor] ADD MEMBER [YourUserName];
GO
tip

Users also need access to the dbo.EncryptString function to generate encrypted passwords:

GRANT EXECUTE ON dbo.EncryptString TO [YourUserName];
GO

Available Functions​

dbo.EncryptString - Password Encryption​

Encrypts passwords using AES-256 encryption for secure storage and transmission.

SELECT dbo.EncryptString('YourPassword')

Returns: Base64-encoded encrypted string

Example:

SELECT dbo.EncryptString('MySecretPassword')
-- Returns: wi1/VHz9s+fp45186iLYYQ==

dbo.xp_RunFastTransfer_secure - Data Transfer​

Wraps the FastTransfer CLI to transfer data between databases with streaming and parallel processing.

Example:

EXEC dbo.xp_RunFastTransfer_secure
@fastTransferDir = 'D:\FastTransfer\',
@sourceConnectionType = 'mssql',
@sourceServer = 'localhost,11433',
@sourceUser = 'FastLogin',
@sourcePasswordSecure = 'wi1/VHz9s+fp45186iLYYQ==',
@sourceDatabase = 'tpch10',
@sourceSchema = 'dbo',
@sourceTable = 'orders',
@targetConnectionType = 'pgcopy',
@targetServer = 'localhost:25433',
@targetUser = 'postgres',
@targetPasswordSecure = 'RAAFe/XJ7O0P1I5T0rJhjQ==',
@targetDatabase = 'postgres',
@targetSchema = 'public',
@targetTable = 'orders',
@loadmode = 'Truncate',
@method = 'Ntile',
@distributeKeyColumn = 'o_orderkey',
@degree = 12,
@mapmethod = 'Name',
@debug = 1,
@noBanner = 0,
@useWorkTables = 0,
@loglevel = 'debug'

Output and Logging​

Transfer Metrics​

The xp_RunFastTransfer_secure stored procedure returns a structured result set:

targetdatabasenvarchar(128)
Target database name
targetSchemanvarchar(128)
Target schema name
targetTablenvarchar(128)
Target table name
TotalRowsbigint
Number of rows transferred
TotalColumnsint
Number of columns transferred
TotalCellsbigint
Total cells transferred (rows × columns)
TotalTimeMsbigint
Total execution time in milliseconds
Statusint
Exit code (0 = success, non-zero = error)
StdErrnvarchar(max)
Error message if Status ≠ 0

Example output:

targetdatabase  targetSchema  targetTable  TotalRows  TotalColumns  TotalCells   TotalTimeMs  Status
postgres public orders 15000000 9 135000000 27502 0

Debug Mode​

Set @debug = 1 to output additional information:

  • Complete command line being executed (passwords masked)
  • Full console output from FastTransfer
  • Real-time progress updates
  • Performance metrics
EXEC dbo.xp_RunFastTransfer_secure
@fastTransferDir = 'C:\FastTransfer\latest',
-- ... other parameters ...
@debug = 1 -- Enable verbose logging

Usage Examples​

Transfer a table between two SQL Server instances using parallel processing (12 threads):

-- First, encrypt your password
SELECT dbo.EncryptString('YourPassword')
-- Returns: wi1/VHz9s+fp45186iLYYQ==

-- Then execute the transfer
EXEC dbo.xp_RunFastTransfer_secure
@fastTransferDir = 'C:\FastTransfer\latest\',
@sourceConnectionType = N'mssql',
@sourceServer = N'localhost',
@sourceUser = N'FastUser',
@sourcePasswordSecure = 'wi1/VHz9s+fp45186iLYYQ==',
@sourceDatabase = N'tpch_test',
@sourceSchema = N'dbo',
@sourceTable = N'orders',
@targetConnectionType = N'msbulk',
@targetServer = N'localhost\SS2025',
@targetUser = N'FastUser',
@targetPasswordSecure = 'wi1/VHz9s+fp45186iLYYQ==',
@targetDatabase = N'tpch_test',
@targetSchema = N'dbo',
@targetTable = N'orders_copy',
@loadMode = N'Truncate',
@batchSize = 130000,
@method = N'RangeId',
@distributeKeyColumn = N'o_orderkey',
@degree = 12,
@mapmethod = 'Name',
@runId = N'SQL_to_SQL_Parallel_Transfer';

Resources​

Resources
Copyright © 2026 Architecture & Performance.