-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some code cleaning and added the documentation
- Loading branch information
1 parent
5cdfb9a
commit df22f3c
Showing
4 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
theme: jekyll-theme-slate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# ZimLabs.Database.MsSql | ||
|
||
![Nuget](https://img.shields.io/nuget/v/ZimLabs.Database.MySql) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/InvaderZim85/ZimLabs.Database.MySql) | ||
|
||
This project provides a simple way to create a connection to a MSSQL database. | ||
|
||
## Installation | ||
|
||
You can install this package via NuGet or download the sources. | ||
|
||
```powershell | ||
Install-Package ZimLabs.Database.MySql | ||
``` | ||
|
||
## Usage | ||
The usage of the connector is very easy. | ||
|
||
The package provides for differen constructors: | ||
|
||
```csharp | ||
using ZimLabs.Database.MySql; | ||
|
||
// 1: Constructor with server and database name. | ||
var connector = new Connector("Server", "Database", "User", "Password", 3306); // The port is optional. Default value is 3306 | ||
// 2: Constructor with server, database, user and password (this time as SecureString) | ||
var connector = new Connector("Server", "Database", "User", "Password".ToSecureString(), 3306); | ||
|
||
// 3: Constructor with a defined connection string | ||
var conString = new MySqlConnectionStringBuilder | ||
{ | ||
Server = "Server", | ||
Database = "Database", | ||
UserID = "User", | ||
Password = "Password", | ||
Port = 3306 | ||
}.ConnectionString.ToSecureString(); | ||
|
||
var connector = new Connector(conString); | ||
|
||
// 4: Constructor with settings class | ||
var settings = new DatabaseSettings | ||
{ | ||
Server = "127.0.0.1", | ||
Database = "MyFancyDatabase", | ||
UserId = "Username", | ||
Password = "Password".ToSecureString(), | ||
Port = 3306 | ||
}; | ||
|
||
var connector = new Connector(settings); | ||
``` | ||
|
||
> **NOTE**: If you use the constructor `Connector(string dataSource, string initialCatalog)` the value for the parameter `IntegratedSecurity` will be set to `true`. | ||
> **NOTE**: The extension method `ToSecureString()` is located in the `Helper` class, which is a part of the package. | ||
## Example | ||
Here a small example (with usage of [Dapper](https://dapper-tutorial.net)) | ||
|
||
```csharp | ||
// The settings | ||
var settings = new DatabaseSettings | ||
{ | ||
Server = "127.0.0.1", | ||
Database = "MyFancyDatabase", | ||
UserId = "Username", | ||
Password = "Password".ToSecureString(), | ||
Port = 3306 | ||
}; | ||
|
||
var connector = new Connector(settings); | ||
|
||
// Perform a query | ||
const string query = "SELECT Id, Name, Mail FROM person AS p"; | ||
|
||
var personList = connector.Connection.Query<Person>(query).ToList(); | ||
``` |