-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.cs
More file actions
98 lines (86 loc) · 2.64 KB
/
Database.cs
File metadata and controls
98 lines (86 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using MySql.Data.MySqlClient;
namespace espaceNetSAV
{
class Database
{
private const int _MAX_POOL_SIZE = 100;
private MySqlConnection connection;
private string server;
private string database;
private int port;
private string uid;
private string password;
public Database()
{
try
{
//this.server = "127.0.0.1"; //local server
//this.uid = "root";
//this.password = "";
this.server = "192.168.1.2"; //Remote server A.K.A Actual Server
this.uid = "espacenet";
this.password = "123456";
this.port = 3306;
this.database = "espaceNetSav";
string connectionString = "Server=" + server + ";Port= " + port + ";" + "Database=" + database + ";" + "Uid=" + uid + ";" + "Pwd=" + password + ";Max Pool Size= " + _MAX_POOL_SIZE;
this.connection = new MySqlConnection(connectionString);
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
#region Methodes
//open the connection
public bool openConnection()
{
try
{
if (!(this.connection.State == System.Data.ConnectionState.Open))
{
this.connection.Open();
}
return true;
}
catch (MySqlException ex)
{
switch (ex.Number)
{
case 0:
Console.WriteLine("Cannot connect to server, Contact admin");
break;
case 1045:
Console.WriteLine("Invalid credentials, please try again");
break;
}
return false;
}
}
//Close the connection
public bool closeConnection()
{
try
{
if (!(this.connection.State == System.Data.ConnectionState.Closed))
{
this.connection.Close();
}
return true;
}
catch (MySqlException ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
public MySqlConnection getConnection()
{
return this.connection;
}
#endregion
#region Query Methodes
#endregion
}
}