DbaClientX is a lightweight database client for .NET and PowerShell. It keeps the database-specific work in provider libraries and exposes a small PowerShell surface for pleasant data movement, query execution, transactions, and bulk writes.
DbaClientX is meant to be the thin, reusable database layer behind higher-level tooling. For example, PSWriteOffice can focus on fast Excel import/export while DbaClientX handles provider-specific database writes. The PowerShell module stays small and operator-friendly; the heavy database logic remains in C#.
Use it when you need:
- one codebase for SQL Server, PostgreSQL, MySQL, SQLite, and Oracle
- sync and async query execution
- parameterized commands and provider-specific parameter type preservation
- transaction helpers that commit on success and roll back on failure
- provider-native bulk insert paths for staging tables and direct table writes
- PowerShell cmdlets for quick scripts, scheduled jobs, and data movement
| Provider | NuGet package | PowerShell query cmdlets | Bulk write | Transaction helper |
|---|---|---|---|---|
| SQL Server | DBAClientX.SqlServer | Invoke-DbaXQuery, Invoke-DbaXNonQuery |
Write-DbaXTableData -Provider SqlServer |
Invoke-DbaXTransaction |
| PostgreSQL | DBAClientX.PostgreSql | Invoke-DbaXPostgreSql, Invoke-DbaXPostgreSqlNonQuery |
Write-DbaXTableData -Provider PostgreSql |
Invoke-DbaXPostgreSqlTransaction |
| MySQL | DBAClientX.MySql | Invoke-DbaXMySql, Invoke-DbaXMySqlNonQuery, Invoke-DbaXMySqlScalar |
Write-DbaXTableData -Provider MySql |
Invoke-DbaXMySqlTransaction |
| SQLite | DBAClientX.SQLite | Invoke-DbaXSQLite |
Write-DbaXTableData -Provider SQLite |
Invoke-DbaXSQLiteTransaction |
| Oracle | DBAClientX.Oracle | Invoke-DbaXOracle, Invoke-DbaXOracleNonQuery, Invoke-DbaXOracleScalar |
Write-DbaXTableData -Provider Oracle |
Invoke-DbaXOracleTransaction |
PowerShell:
Install-Module DbaClientX -Scope CurrentUser.NET:
dotnet add package DBAClientX.Core
dotnet add package DBAClientX.SqlServer
dotnet add package DBAClientX.PostgreSql
dotnet add package DBAClientX.MySql
dotnet add package DBAClientX.SQLite
dotnet add package DBAClientX.OracleInstall only the provider packages you need.
Invoke-DbaXQuery `
-Server 'sql01' `
-Database 'App' `
-Query 'SELECT TOP (10) * FROM dbo.Users' `
-Credential $CredentialInvoke-DbaXPostgreSql -Server 'pg01' -Database 'app' -Query 'select * from users limit 10' -Credential $Credential
Invoke-DbaXMySql -Server 'mysql01' -Database 'app' -Query 'select * from users limit 10' -Credential $Credential
Invoke-DbaXOracle -Server 'ora01' -Database 'service' -Query 'select * from users fetch first 10 rows only' -Credential $Credential
Invoke-DbaXSQLite -Database '.\app.db' -Query 'select * from users limit 10'New-DbaXQuery -TableName 'dbo.Users' -Limit 50 -CompileWrite-DbaXTableData accepts DataTable, DataView, IDataReader, DataRow, hashtables, and regular PowerShell objects from the pipeline. This makes it useful for staging-table imports and direct table writes.
$rows = @(
[pscustomobject]@{ Id = 1; DisplayName = 'Alice' }
[pscustomobject]@{ Id = 2; DisplayName = 'Bob' }
)
$rows | Write-DbaXTableData `
-Provider SqlServer `
-ConnectionString 'Server=.;Database=App;Encrypt=True;TrustServerCertificate=True;Integrated Security=True' `
-DestinationTable 'dbo.ImportUsers' `
-BatchSize 5000 `
-PassThruWith PSWriteOffice:
Import-OfficeExcel .\Users.xlsx -AsDataTable |
Write-DbaXTableData `
-Provider PostgreSql `
-ConnectionString 'Host=localhost;Database=app;Username=user;Password=secret' `
-DestinationTable 'public.import_users' `
-BatchSize 5000Invoke-DbaXTransaction -Server 'sql01' -Database 'App' -ScriptBlock {
param($client)
$client.ExecuteNonQuery(
'sql01',
'App',
$true,
'UPDATE dbo.Users SET IsActive = 1 WHERE Id = 1',
$null,
$true
)
}Transaction helpers honor -WhatIf and -Confirm, commit when the script block succeeds, roll back on failure, and dispose the provider client in finally.
using DBAClientX;
using System.Data;
using var sqlServer = new SqlServer {
ReturnType = ReturnType.DataTable
};
var result = await sqlServer.QueryAsync(
"SQL1",
"master",
integratedSecurity: true,
query: "SELECT TOP 1 * FROM sys.databases");
if (result is DataTable table) {
foreach (DataRow row in table.Rows) {
Console.WriteLine(row["name"]);
}
}using System.Data;
using DBAClientX;
using var sqlServer = new SqlServer();
var table = new DataTable();
table.Columns.Add("Id", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Rows.Add(1, "Example");
sqlServer.BulkInsert(
server: "SQL1",
database: "App",
integratedSecurity: true,
table: table,
destinationTable: "dbo.ImportUsers",
batchSize: 1000,
bulkCopyTimeout: 60);var sqlServer = DBAClientX.SqlServer.BuildConnectionString("SQL1", "App", integratedSecurity: true, ssl: true);
var postgres = DBAClientX.PostgreSql.BuildConnectionString("localhost", "app", "user", "password", ssl: true);
var mysql = DBAClientX.MySql.BuildConnectionString("localhost", "app", "user", "password", ssl: true);
var sqlite = DBAClientX.SQLite.BuildConnectionString("app.db");using DBAClientX.QueryBuilder;
var query = new Query()
.Select("*")
.From("users")
.Where("name", "Alice")
.Where("age", ">", 30);
var (sql, parameters) = QueryBuilder.CompileWithParameters(query);| Component | Windows | Linux/macOS |
|---|---|---|
| Provider libraries | .NET Framework 4.7.2, .NET 8.0, .NET 10.0 | .NET 8.0, .NET 10.0 |
| PowerShell binary module | .NET Framework 4.7.2, .NET 8.0 | .NET 8.0 |
| Examples | .NET 8.0, .NET 10.0 | .NET 8.0, .NET 10.0 |
| Benchmarks | .NET 8.0, .NET 10.0 | .NET 8.0, .NET 10.0 |
| Path | Purpose |
|---|---|
DbaClientX.Core |
Shared base client, retry logic, query builder, connection validation, invoker abstractions |
DbaClientX.SqlServer |
SQL Server provider |
DbaClientX.PostgreSql |
PostgreSQL provider |
DbaClientX.MySql |
MySQL provider |
DbaClientX.SQLite |
SQLite provider |
DbaClientX.Oracle |
Oracle provider |
DbaClientX.PowerShell |
Binary cmdlets and PowerShell-facing helpers |
Module |
PowerShell module manifest, script functions, examples, Pester tests, and build script |
DbaClientX.Examples |
C# usage examples |
DbaClientX.Tests |
xUnit tests |
DbaClientX.Benchmarks |
BenchmarkDotNet scenarios |
Build |
Project release configuration |
- PowerShell examples:
Module/Examples - C# examples:
DbaClientX.Examples - Benchmarks:
DbaClientX.Benchmarks
Useful example files:
Example.QuerySqlServer.ps1Example.QueryPostgreSql.ps1Example.QueryMySql.ps1Example.QueryOracle.ps1Example.QuerySQLite.ps1BulkInsertExample.csTransactionExample.csParameterizedQueryExample.cs
dotnet restore DbaClientX.sln
dotnet build DbaClientX.sln -c Release
dotnet test DbaClientX.sln -c Release --framework net8.0PowerShell module tests:
.\Module\DbaClientX.Tests.ps1Package build:
$env:RefreshPSD1Only = 'false'
.\Module\Build\Build-Module.ps1
Remove-Item Env:\RefreshPSD1OnlyPackage publishing is intentionally manual in this repository because releases are signed locally with the USB key certificate.
Generate a build plan:
pwsh.exe -NoLogo -NoProfile -File .\Build\Build-Project.ps1 -Plan $trueBuild signed packages locally:
pwsh.exe -NoLogo -NoProfile -File .\Build\Build-Project.ps1 -Build $true -PublishNuget $false -PublishGitHub $falsePublish NuGet and GitHub together in one versioned run:
pwsh.exe -NoLogo -NoProfile -File .\Build\Build-Project.ps1 -PublishNuget $true -PublishGitHub $trueBuild configuration lives in Build/project.build.json, and artifacts are generated under Artefacts/ProjectBuild.
- The solution enables nullable reference types and .NET analyzers via
Directory.Build.props. - SourceLink is enabled for provider projects for easier debugging into packages.
- SQL Server uses
Microsoft.Data.SqlClient. - PowerShell 7 package builds use a module-scoped AssemblyLoadContext so DbaClientX can coexist more safely with other modules that load overlapping assemblies.
- The release wrapper treats version updates as part of publishing. If you intentionally need a replay-only publish for already-versioned artifacts, pass
-UpdateVersions $falseexplicitly.