Skip to content
Dead simple integration tests with SQL Server or Postgres throwaway databases that are created on the fly, used briefly then disposed of automagically.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Easily create a disposable database that integration tests dead simple for Sql server using throwaway databases.

Available Packages

Package Supports Version
ThrowawayDb SQL Server Nuget
ThrowawayDb.Postgres SQL Server Nuget

Using SQL Server

Install ThrowawayDb from Nuget

dotent add package ThrowawayDb

Use from your code

public static void Main(string[] args)
    using (var database = ThrowawayDatabase.FromLocalInstance("localhost\\SQLEXPRESS"))
        Console.WriteLine($"Created database {database.Name}");

        // - Apply database migrations here if necessary
        // - Seed the database with data
        // - Execute your code against this database

        using (var connection = new SqlConnection(database.ConnectionString))
            using (var cmd = new SqlCommand("SELECT 1", connection))
                var result = Convert.ToInt32(cmd.ExecuteScalar());

In the snippet above, a dummy database with a random name is created using the current local instance of SQL Express on my machine. Moreover, the object database is an IDisposable and will drop the database at the end of the using clause when it's Dispose() is executed. It is that simple!

You can create the throwaway database in multiple ways:

// from Sql Express server locally with Integrated security

// Uses the default instance locally where Data Source = .

// Using SQL Authentication with user credentials and an arbibrary host
ThrowawayDatabase.Create(username: "Zaid", password: "strongPassword", host: "")

// Using a connection string where Initial Catalog is master
ThrowawayDatabase.Create(connectionString: "Data Source=localhost\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True;")

Using PostgreSQL server

Install ThrowawayDb.Postgres from Nuget

dotnet add package ThrowawayDb.Postgres

use from your code:

static void Main(string[] args)
    using (var database = ThrowawayDatabase.Create(username: "postgres", password: "postgres", host: "localhost"))
        using (var connection = new NpgsqlConnection(database.ConnectionString))
            using (var cmd = new NpgsqlCommand("SELECT 1", connection))
                var result = Convert.ToInt32(cmd.ExecuteScalar());
You can’t perform that action at this time.