mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-17 18:39:07 +00:00
31 lines
628 B
C#
31 lines
628 B
C#
using Microsoft.Extensions.Logging;
|
|
using MySqlConnector;
|
|
|
|
namespace CS2_SimpleAdmin
|
|
{
|
|
public class Database
|
|
{
|
|
private readonly string _dbConnectionString;
|
|
|
|
public Database(string dbConnectionString)
|
|
{
|
|
_dbConnectionString = dbConnectionString;
|
|
}
|
|
|
|
public async Task<MySqlConnection> GetConnectionAsync()
|
|
{
|
|
try
|
|
{
|
|
var connection = new MySqlConnection(_dbConnectionString);
|
|
await connection.OpenAsync();
|
|
return connection;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
if (CS2_SimpleAdmin._logger != null)
|
|
CS2_SimpleAdmin._logger.LogCritical("Unable to connect to database");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
} |