Skip to content

Instantly share code, notes, and snippets.

@maiquealmeida
Created April 23, 2015 12:25
Show Gist options
  • Save maiquealmeida/3cf11f2f0c7063971eab to your computer and use it in GitHub Desktop.
Save maiquealmeida/3cf11f2f0c7063971eab to your computer and use it in GitHub Desktop.
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace OcomonDashboardService.Classes
{
public class MySQLDBConnect : IDisposable
{
private MySQLDBConnect() { }
private string databaseName = String.Empty;
public string DatabaseName
{
get { return databaseName; }
set { databaseName = value; }
}
public string Password { get; set; }
private MySqlConnection Connection = null;
private static MySQLDBConnect _instance = null;
public static MySQLDBConnect Instance()
{
if (_instance == null)
_instance = new MySQLDBConnect();
return _instance;
}
public bool IsConnect()
{
bool result = true;
if (Connection == null)
{
if (databaseName == string.Empty)
result = false;
string StrCon = string.Format("Server=localhost; database={0}; UID=UserName; password=your password", databaseName);
Connection = new MySqlConnection(StrCon);
Connection.Open();
result = true;
}
return result;
}
public MySqlConnection GetConnection()
{
return Connection;
}
public void Close()
{
Connection.Close();
}
public void Dispose()
{
if (Connection != null)
{
Connection.Dispose();
Connection = null;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment