Controtex.SqlUtility2
2.0.1
dotnet add package Controtex.SqlUtility2 --version 2.0.1
NuGet\Install-Package Controtex.SqlUtility2 -Version 2.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Controtex.SqlUtility2" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Controtex.SqlUtility2" Version="2.0.1" />
<PackageReference Include="Controtex.SqlUtility2" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Controtex.SqlUtility2 --version 2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Controtex.SqlUtility2, 2.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Controtex.SqlUtility2@2.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Controtex.SqlUtility2&version=2.0.1
#tool nuget:?package=Controtex.SqlUtility2&version=2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Controtex.SqlUtility2
Controtex.SqlUtility2 is a C# library that simplifies querying SQL Server databases and always returns results in structured JSON format.
It supports executing:
- Stored procedures (with or without parameters)
- SQL queries returning tables or scalar values
- Arbitrary SQL commands (e.g. INSERT/UPDATE/DELETE)
- Automatic conversion of all results to
JArray/JObject(via Newtonsoft.Json)
๐ง Features
- โ
JSON output for everything:
JArray/JObject - โ Stored procedure support, including multiple result sets
- โ
Auto-discovery of procedure parameter names via
sys.parameters - โ Parameter binding by name or position
- โ Unified API for querying and executing
- โ Lightweight, dependency-free (aside from Newtonsoft.Json and Microsoft.Data.SqlClient)
๐ฆ Installation
dotnet add package Controtex.SqlUtility2
๐ Basic Usage
var db = new SqlUtility("your-connection-string");
// Get rows from a table
JArray users = db.Table("Users");
// Run a non-query SQL command
int rows = db.ExecuteCommand("DELETE FROM Logs WHERE Level = @level", "level", "Debug");
// Get a single scalar value
object count = db.ExecuteScalar("SELECT COUNT(*) FROM Users");
๐ Calling Stored Procedures
๐งช Example 1: No parameters
JArray? result = db.Call("GetAllUsers");
๐งช Example 2: One parameter
JArray? result = db.Call("GetUsersByRole", "role", "Admin");
Equivalent to:
EXEC GetUsersByRole @role = 'Admin'
๐งช Example 3: Multiple parameters
var result = db.Call("GetUsersByStatus",
new[] { "status", "country" },
"Active", "PL");
๐งช Example 4: All result sets (multi-table)
JObject results = db.CallAllResults("GetDashboardStats", new object[] { 2024 });
// Access results by name
JArray stats = (JArray)results["Stats"];
JArray errors = (JArray)results["Errors"];
๐งช Example 5: Get single object
JObject? user = db.CallOne("GetUserById", 123);
string? name = user?["Name"]?.Value<string>();
๐ Table Queries
Basic table data
JArray? orders = db.Table("Orders", "UserId = @id", "id", 42);
One row from a table
JObject? latestOrder = db.TableOne("Orders", "UserId = @id", "Date DESC", "id", 42);
Top N results with order
JArray? topItems = db.TableTop("Products", 5, "Category = @cat", "Price DESC", new[] { "cat" }, "Books");
๐ Execute SQL Commands
Non-query
int affected = db.ExecuteCommand("UPDATE Users SET Active = 0 WHERE LastLogin < @date", "date", DateTime.Now.AddMonths(-6));
Scalar result
object result = db.ExecuteScalar("SELECT COUNT(*) FROM Users WHERE Active = 1");
๐ License
MIT License
โ๏ธ Support
Issues, suggestions, or feedback? Please post them on the NuGet package page.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- Microsoft.Data.SqlClient (>= 6.0.2)
- Newtonsoft.Json (>= 13.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added readme