GnomeStack.Data.Mssql 0.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package GnomeStack.Data.Mssql --version 0.1.2                
NuGet\Install-Package GnomeStack.Data.Mssql -Version 0.1.2                
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="GnomeStack.Data.Mssql" Version="0.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GnomeStack.Data.Mssql --version 0.1.2                
#r "nuget: GnomeStack.Data.Mssql, 0.1.2"                
#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.
// Install GnomeStack.Data.Mssql as a Cake Addin
#addin nuget:?package=GnomeStack.Data.Mssql&version=0.1.2

// Install GnomeStack.Data.Mssql as a Cake Tool
#tool nuget:?package=GnomeStack.Data.Mssql&version=0.1.2                

GnomeStack.Data.Mssql

Provides Management Sql statements for Sql Server like creating/dropping databases, users, logins, or getting database sizes, info on resource usage, etc.

The library is built on top of GnomeStack.Data which uses dapper and provides extension methods for IDbConnection and Dapper that enables classes or structs that implement ISqlStatementBuilder to be executed.

Usage

// this sample comes from tests. Please use a better password.
using var connection = new SqlConnection(this.ConnectString);
await connection.ExecAsync(new MssqlCreateDatabase("king_bob_db"));
await connection.ExecAsync(new MssqlCreateLogin("king_bob_login", "p@ssw0rd"));

this.Writer.WriteLine("Creating cs 2 with database king_bob_db...");
var dbcsBuilder = new SqlConnectionStringBuilder(this.ConnectString)
{
    InitialCatalog = "king_bob_db",
};
var dbcs = dbcsBuilder.ToString();
var conn2 = new SqlConnection(dbcs);

this.Writer.WriteLine("Creating user...");
await conn2.ExecAsync(new MssqlCreateUser("king_bob_user", "king_bob_login"));

this.Writer.WriteLine("Adding user to role...");
await conn2.ExecAsync(new MssqlAddRoleMember("db_owner", "king_bob_user"));

var hasUserResult = await conn2.ScalarAsResultAsync<int>(new MssqlSelectUserExists("king_bob_user"));
Assert.False(hasUserResult.IsError);
Assert.True(hasUserResult.Unwrap() == 1);

this.Writer.WriteLine("Creating cs 2 with user king_bob_login...");
dbcsBuilder.UserID = "king_bob_login";
dbcsBuilder.Password = "p@ssw0rd";
dbcs = dbcsBuilder.ToString();
var conn3 = new SqlConnection(dbcs);

this.Writer.WriteLine("Testing connection as new user...");
var selectResult = await conn3.ScalarAsResultAsync<int>("SELECT 1");
Assert.False(selectResult.IsError);
Assert.True(selectResult.Unwrap() == 1);

conn3.Dispose();

this.Writer.WriteLine("Removing user from role...");
await conn2.ExecAsync(new MssqlDropRoleMember("db_owner", "king_bob_user"));

this.Writer.WriteLine("Dropping user...");
await conn2.ExecAsync(new MssqlDropUser("king_bob_user"));

hasUserResult = await conn2.ScalarAsResultAsync<int>(new MssqlSelectUserExists("king_bob_user"));
Assert.False(hasUserResult.IsError);
conn2.Dispose();

// this extension method gets all the process ids for the given login
// and kills them before dropping the login.
await connection.DropMssqlLoginAsync("king_bob_login");
await connection.ExecAsync(new MssqlDropConnections("king_bob_db"));
await connection.ExecAsync(new MssqlDropDatabase("king_bob_db"));

MIT License

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.3 239 12/6/2023
0.1.2 152 11/13/2023

# CHANGE LOG

## 0.0.0 initial creation

- created.