using System.Data;
using System.Configuration;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
///
/// Summary description for Connection
///
public class Connection
{
public Connection()
{
//
// TODO: Add constructor logic here
//
}
public MySqlConnection MyConnection;
public MySqlDataReader DataReader;
public MySqlCommand Command;
private string mySqlConnectionString = "Connection String";
///
///
///
public void CloseConn()
{
if (MyConnection != null)
{
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
MyConnection.Dispose();
}
}
///
///
///
///
public MySqlConnection CreateConn()
{
if (MyConnection == null) { MyConnection = new MySqlConnection(); };
if (MyConnection.ConnectionString == string.Empty || MyConnection.ConnectionString == null)
{
try
{
MyConnection.ConnectionString = mySqlConnectionString;
MyConnection.Open();
}
catch (Exception)
{
if (MyConnection.State != ConnectionState.Closed)
{
MyConnection.Close();
}
MyConnection.ConnectionString = mySqlConnectionString;
MyConnection.Open();
}
return MyConnection;
}
if (MyConnection.State != ConnectionState.Open)
{
try
{
MyConnection.ConnectionString = mySqlConnectionString;
MyConnection.Open();
}
catch (Exception)
{
if (MyConnection.State != ConnectionState.Closed)
{
MyConnection.Close();
}
MyConnection.ConnectionString = mySqlConnectionString;
MyConnection.Open();
}
}
return MyConnection;
}
}
No comments:
Post a Comment