diff --git a/ZimLabs.Database.MySql/Connector.cs b/ZimLabs.Database.MySql/Connector.cs index d060168..6743ebc 100644 --- a/ZimLabs.Database.MySql/Connector.cs +++ b/ZimLabs.Database.MySql/Connector.cs @@ -37,7 +37,8 @@ public MySqlConnection Connection { get { - if (_connection == null || _connection.State == ConnectionState.Closed || _connection.State == ConnectionState.Broken) + if (_connection == null || _connection.State == ConnectionState.Closed || + _connection.State == ConnectionState.Broken) CreateConnection(); return _connection; diff --git a/ZimLabs.Database.MySql/ZimLabs.Database.MySql.csproj b/ZimLabs.Database.MySql/ZimLabs.Database.MySql.csproj index 458860e..0bca1b1 100644 --- a/ZimLabs.Database.MySql/ZimLabs.Database.MySql.csproj +++ b/ZimLabs.Database.MySql/ZimLabs.Database.MySql.csproj @@ -13,8 +13,8 @@ https://github.com/InvaderZim85/ZimLabs.Database.MySql git Helper, Database, MySql, Connector - 1.0.2 - Made the helper function public which provides two methods to convert a string into a secure string and the otherway round + 1.0.3 + Minor changes (code cleaning) 1.0.2.0 1.0.2.0 diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 0000000..c741881 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-slate \ No newline at end of file diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..7e37da4 --- /dev/null +++ b/docs/index.md @@ -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(query).ToList(); +``` \ No newline at end of file