Skip to content

Glimpse with SQL Server

Joshua Russo edited this page Jan 14, 2016 · 2 revisions

The Glimpse wrapper in combination SQL server has a limitation in regards to Bulk Insert functionality.

The BulkInsert class is initialized with a concrete instance of ADO.Net SqlConnection and SqlTranscation, because the functionality is SQL Server specific.

Glimpse replaces the SqlConnection : DbConnection instance with a GlimpseDbConnection : DbConnection instance, and exposes the original connection instance via the InnerConnection property.

To enable BulkInsert while using Glimpse you will need to add the following static Func property overrides.

SqlBulkCopyHelper.SqlConnectionResolver = dbConn =>
{
    var glimpseConn = (GlimpseDbConnection)dbConn;
    return (SqlConnection)glimpseConn.InnerConnection;
};

SqlBulkCopyHelper.SqlTransactionResolver = dbTran =>
{
    var glimpseTran = (GlimpseDbTransaction)dbTran;
    return (SqlTransaction)glimpseTran.InnerTransaction;
};

This effectively bypasses Glimpse for Bulk Insert actions.