SafeConnection 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package SafeConnection --version 1.0.6
                    
NuGet\Install-Package SafeConnection -Version 1.0.6
                    
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="SafeConnection" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SafeConnection" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="SafeConnection" />
                    
Project file
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 SafeConnection --version 1.0.6
                    
#r "nuget: SafeConnection, 1.0.6"
                    
#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 SafeConnection@1.0.6
                    
#: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=SafeConnection&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=SafeConnection&version=1.0.6
                    
Install as a Cake Tool

About

SafeConnection is a robust library designed to facilitate secure and efficient database connections. It provides a comprehensive set of features including:

  • Secure Connections: Ensures all database connections are secure and encrypted. Additionally, it closes the passed connection explicitly.
  • Caching: Implements in-memory caching to reduce database load and improve performance.
  • Logging: Integrated logging capabilities to track database operations and errors.
  • Compatibility: Supports multiple .NET versions including .NET Standard 3.1 and .NET 6.0.
  • Ease of Use: Simple and intuitive API for quick integration into your projects.

This library is ideal for applications that require reliable and secure database interactions with minimal overhead.

Usage Instructions

To use SafeConnection, simply install the package via NuGet and add the following code to your project:

  1. Install the Package: Add the SafeConnection package to your project using NuGet:

     dotnet add package SafeConnection
    
  2. Inject the Service: Inject the SafeConnection service into your application as Singleton:

     builder.Services.AddSingleton<SafeConnection>(_ => new SafeConnection(
     	appName: builder.Environment.ApplicationName, // It will be used in the logs.
     	environment: builder.Environment.EnvironmentName, // It will be used in the logs.
     	sqlConnectionString: builder.Configuration.GetConnectionString("Your_Sql_log_connectionString"), // Where the logs will be stored.
     	sqlTable: "App_Logs", // The table where the logs will be stored.
     	cacheExpirationMinutes: builder.Configuration.GetValue<int>("CacheExpirationInMinutes") // The expiration time of the cache in minutes.
     ));
    
  3. Use the Service: Use the SafeConnection service in your application to interact with the database:

     public class YourService
     {
     	private readonly SafeConnection _safeConnection;
    
     	// Inject SafeConnection service
     	public YourService(SafeConnection safeConnection)
     	{
     		_safeConnection = safeConnection;
     	}
    
     	// Use SafeConnection to execute SQL queries
     	public async Task<IEnumerable<YourModel>> GetYourData()
     	{
     		var query = @"SELECT field1, field2 from your_table";
    
            var connection = new OleDbConnection("Your__query_string");		
     		return await _safeConnection.QueryAsync<YourModel>(connection, query, "YourCacheKey");
     	}
     }
    
  4. The SQL table structure:

     CREATE TABLE App_Logs (
     	Id int IDENTITY(1,1) NOT NULL,
     	[DateTime] datetime NOT NULL,
     	App varchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
     	Env varchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
     	Query varchar(500) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
     	Cached bit NOT NULL,
     	Duration real NOT NULL,
     	[Rows] int NOT NULL,
     	Columns int NOT NULL,
     	Kb int NULL,
     	CONSTRAINT App_Logs_PK PRIMARY KEY (Id)
     );
    
  5. Enjoy!

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 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.1 is compatible. 
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
1.0.11 146 7/1/2026
1.0.10 182 1/8/2026
1.0.9 163 1/8/2026
1.0.8 326 8/20/2024
1.0.7 259 8/16/2024
1.0.6 227 8/16/2024
1.0.5 225 8/16/2024
1.0.4 231 8/16/2024
1.0.3 240 8/16/2024
1.0.1 231 8/16/2024
1.0.0 241 8/14/2024