DatabaseOperations 1.1.20
Prefix ReservedSee the version list below for details.
dotnet add package DatabaseOperations --version 1.1.20
NuGet\Install-Package DatabaseOperations -Version 1.1.20
<PackageReference Include="DatabaseOperations" Version="1.1.20" />
paket add DatabaseOperations --version 1.1.20
#r "nuget: DatabaseOperations, 1.1.20"
// Install DatabaseOperations as a Cake Addin #addin nuget:?package=DatabaseOperations&version=1.1.20 // Install DatabaseOperations as a Cake Tool #tool nuget:?package=DatabaseOperations&version=1.1.20
DatabaseOperations
The purpose of this library is to provide the consumer with tools to perform database operations. The library has been designed for use in deployment/utilities to automate the tasks usually done manually.
NOTE:
Microsoft SQL Server Databases only.
Introduction
I have used tools in Microsoft SQL Server Management Studio or Azure Data Studio to back up databases. The programs provided me with the tools needed to conduct the tasks required.
The problem came when I had to create a tool used in C# to do the same process for me. Now the process is easy using a small SQL script. However, when I went looking for a library on NuGet for me to use, there were none.
So, I made this library that I am now putting out there for other people to use.
Description
This repo is a library that will grow with more features to help automate database operations. I welcome any feedback and features to add.
Usages
There are more details on the project wiki. Here are some basics.
Backup Operator
The BackupOperator
is the only operator in the project at the moment. Other operators will be added in due course.
Construction
The constructor requires no parameters.
Signature:
public BackupOperator()
BackupOperator backupOperator = new();
Backup Database methods
There are two methods to enable the user to backup a database. Both methods have an async
version.
Original Versions - will be made obsolete
public OperationResult BackupDatabase(ConnectionOptions options)
public async Task<OperationResult> BackupDatabaseAsync(
ConnectionOptions options,
CancellationToken token = default)
New Versions - the preferred method
public OperationResult BackupDatabase(
string connectionString,
Action<OperatorOptions>? options = null)
public async Task<OperationResult> BackupDatabaseAsync(
string connectionString,
Action<OperatorOptions>? options = null,
CancellationToken token = default)
The OperatorOptions
class has defaults set, so can be left out of the call. This would mean the backup would be saved to the default location used by SQL Server and the execution timeout will be set to one hour.
To perform the backup operation synchronously:
const string connectionString = @"server=MyComputer\SQLDEV;database=TestDatabase;Integrated Security=SSPI;Connect Timeout=5;";
const string backupPath = @"E:\Database\Backups\";
OperationResult result = backupOperator.BackupDatabase(connectionString, options => {
options.BackupPath = @"E:\Database\Backups\";
options.Timeout = 600;
});
To perform the backup asynchronously (for many backup operations):
// Define the connection strings.
const string connectionStringOne = @"server=MyComputer\SQLDEV;database=DatabaseOne;Integrated Security=SSPI;Connect Timeout=5;";
const string connectionStringTwo = @"server=MyComputer\SQLDEV;database=DatabaseTwo;Integrated Security=SSPI;Connect Timeout=5;";
const string connectionStringThree = @"server=MyComputer\SQLDEV;database=DatabaseTwo;Integrated Security=SSPI;Connect Timeout=5;";
// Define the backup path.
const string backupPath = @"E:\Database\Backups\";
var cancellationSource = new CancellationTokenSource();
var token = cancellationSource.Token;
// Start the backup operations in an asynchronous manor.
Task<OperationResult> resultOne = backupOperator.BackupDatabaseAsync(connectionStringOne, options => {
options.BackupPath = backupPath;
}, token);
Task<OperationResult> resultTwo = backupOperator.BackupDatabaseAsync(connectionStringTwo, options => {
options.BackupPath = backupPath;
}, token);
Task<OperationResult> resultThree = backupOperator.BackupDatabaseAsync(connectionStringThree, options => {
options.BackupPath = backupPath;
}, token);
await Task.WhenAll(resultOne, resultTwo, resultThree).ConfigureAwait(false);
// Get the results.
OperationResult taskOne = await resultOne.ConfigureAwait(false);
OperationResult taskTwo = await resultTwo.ConfigureAwait(false);
OperationResult taskThree = await resultThree.ConfigureAwait(false);
Cancellation of the operation
The CancellationTokenSource
object can be created with a timeout in milliseconds or a TimeSpan
.
The token source can be cancelled from any event, or when the timeout is reached.
If no token is supplied to the call, it will create one, but the calling application will not be able to raise the cancellation of the task.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 is compatible. 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. |
-
net6.0
- Azure.Identity (>= 1.11.4)
- FluentValidation (>= 11.9.0)
- Microsoft.Data.SqlClient (>= 5.2.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 7.5.1)
- System.Drawing.Common (>= 8.0.4)
- System.IdentityModel.Tokens.Jwt (>= 7.5.1)
- System.Net.Http (>= 4.3.4)
- System.Text.RegularExpressions (>= 4.3.1)
- Useful.Extensions (>= 3.0.7)
-
net7.0
- Azure.Identity (>= 1.11.4)
- FluentValidation (>= 11.9.0)
- Microsoft.Data.SqlClient (>= 5.2.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 7.5.1)
- System.Drawing.Common (>= 8.0.4)
- System.IdentityModel.Tokens.Jwt (>= 7.5.1)
- System.Net.Http (>= 4.3.4)
- System.Text.RegularExpressions (>= 4.3.1)
- Useful.Extensions (>= 3.0.7)
-
net8.0
- Azure.Identity (>= 1.11.4)
- FluentValidation (>= 11.9.0)
- Microsoft.Data.SqlClient (>= 5.2.0)
- Microsoft.IdentityModel.JsonWebTokens (>= 7.5.1)
- System.Drawing.Common (>= 8.0.4)
- System.IdentityModel.Tokens.Jwt (>= 7.5.1)
- System.Net.Http (>= 4.3.4)
- System.Text.RegularExpressions (>= 4.3.1)
- Useful.Extensions (>= 3.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
See the details at the following link.
https://github.com/Daeer-Projects/DatabaseOperations/wiki/Release-Notes