DatabaseOperations 1.0.3
Prefix ReservedSee the version list below for details.
dotnet add package DatabaseOperations --version 1.0.3
NuGet\Install-Package DatabaseOperations -Version 1.0.3
<PackageReference Include="DatabaseOperations" Version="1.0.3" />
paket add DatabaseOperations --version 1.0.3
#r "nuget: DatabaseOperations, 1.0.3"
// Install DatabaseOperations as a Cake Addin
#addin nuget:?package=DatabaseOperations&version=1.0.3
// Install DatabaseOperations as a Cake Tool
#tool nuget:?package=DatabaseOperations&version=1.0.3
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.
Usages
There are more details on the project wiki. Here are some basics.
Backup Operator
To create a new instance of the BackupOperator
:
var backupOperator = new BackupOperator();
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\";
var result = backupOperator.BackupDatabase(new ConnectionOptions(connectionString, backupPath));
To perform the backup asynchronously (for many backup operations):
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;";
const string backupPath = @"E:\Database\Backups\";
var cancellationSource = new CancellationTokenSource();
var token = cancellationSource.Token;
var resultOne = backupOperator.BackupDatabaseAsync(new ConnectionOptions(connectionStringOne, backupPath), token);
var resultTwo = backupOperator.BackupDatabaseAsync(new ConnectionOptions(connectionStringTwo, backupPath), token);
var resultThree = backupOperator.BackupDatabaseAsync(new ConnectionOptions(connectionStringThree, backupPath), token);
await Task.WhenAll(resultOne, resultTwo, resultThree).ConfigureAwait(false);
var taskOne = await resultOne.ConfigureAwait(false);
var taskTwo = await resultTwo.ConfigureAwait(false);
var 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 | net5.0 is compatible. 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 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.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. |
-
.NETCoreApp 3.1
- FluentValidation (>= 11.0.2)
- Microsoft.SqlServer.SqlManagementObjects (>= 161.47021.0)
- Newtonsoft.Json (>= 13.0.1)
- System.IO.Abstractions (>= 17.0.15)
- System.Net.Http (>= 4.3.4)
- System.Text.RegularExpressions (>= 4.3.1)
- Useful.Extensions (>= 3.0.1)
-
.NETStandard 2.1
- FluentValidation (>= 11.0.2)
- Microsoft.SqlServer.SqlManagementObjects (>= 161.47021.0)
- Newtonsoft.Json (>= 13.0.1)
- System.IO.Abstractions (>= 17.0.15)
- System.Net.Http (>= 4.3.4)
- System.Text.RegularExpressions (>= 4.3.1)
- Useful.Extensions (>= 3.0.1)
-
net5.0
- FluentValidation (>= 11.0.2)
- Microsoft.SqlServer.SqlManagementObjects (>= 161.47021.0)
- Newtonsoft.Json (>= 13.0.1)
- System.IO.Abstractions (>= 17.0.15)
- System.Net.Http (>= 4.3.4)
- System.Text.RegularExpressions (>= 4.3.1)
- Useful.Extensions (>= 3.0.1)
-
net6.0
- FluentValidation (>= 11.0.2)
- Microsoft.SqlServer.SqlManagementObjects (>= 161.47021.0)
- Newtonsoft.Json (>= 13.0.1)
- System.IO.Abstractions (>= 17.0.15)
- System.Net.Http (>= 4.3.4)
- System.Text.RegularExpressions (>= 4.3.1)
- Useful.Extensions (>= 3.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.
See the details at the following link.
https://github.com/Daeer-Projects/DatabaseOperations/wiki/Release-Notes