https://github.com/notilya4/notilya.sqlconnectionstring.extensions
📦 Extension for IConfiguration to get sql connection string
https://github.com/notilya4/notilya.sqlconnectionstring.extensions
c-sharp connection-string dotnet extensions
Last synced: 7 months ago
JSON representation
📦 Extension for IConfiguration to get sql connection string
- Host: GitHub
- URL: https://github.com/notilya4/notilya.sqlconnectionstring.extensions
- Owner: NotIlya4
- License: mit
- Created: 2023-08-20T11:24:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-14T18:58:16.000Z (over 2 years ago)
- Last Synced: 2025-08-27T15:55:34.100Z (8 months ago)
- Topics: c-sharp, connection-string, dotnet, extensions
- Language: C#
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 📦 NotIlya.SqlConnectionString.Extensions [](https://www.nuget.org/packages/NotIlya.SqlConnectionString.Extensions)
Several extensions for `IConfiguration` that help retrieve connection strings, primarily designed for SQL Server (MSSQL) as I'm using `SqlConnectionStringBuilder` under the hood.
## Quickstart
You can have config like this:
```json
{
"SqlConnectionString": {
"Server": "localhost,1433",
"Database": "TestDb"
}
}
```
Or like this:
```json
{
"SqlConnectionString": "localhost,1433;Database=TestDb"
}
```
And you can get it using `config.GetSqlConnectionString()`.
## Custom section
To specify your own section use `key` parameter in any method:
```json
{
"SqlServer": {
"Server": "localhost,1433",
"Database": "TestDb"
}
}
```
Get it by `config.GetSqlConnectionString("SqlServer")`.
## Development defaults
There is also method that has predefined defaults for development environments. Your empty config:
```json
{
}
```
Using this `config.GetDevelopmentSqlConnectionString()` empty config will be equivalent to:
```json
{
"SqlConnectionString": {
"Server": "localhost,1433",
"User Id": "SA",
"Password": "1tsJusT@S@mpleP@ssword!",
"MultipleActiveResultSets": true,
"TrustServerCertificate": true
}
}
```
Of course you can override any of this values by providing them in config.
## SqlConnectionStringBuilder
My extensions built on top of `SqlConnectionStringBuilder` and instead of raw connection string you can get builder. Instead of `GetSqlConnectionString` use `GetSqlConnectionStringBuilder` and instead of `GetDevelopmentSqlConnectionString` use `GetDevelopmentSqlConnectionStringBuilder`.