Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace Mysql
- {
- class DB
- {
- private MySqlConnection connection;
- private string server;
- private string user;
- private string port;
- private string pass;
- private string db;
- public DB()
- {
- Initialize();
- }
- private void Initialize()
- {
- server = Program.form1.HOST_TXT.Text;
- user = Program.form1.USER_TXT.Text;
- port = "3306";
- pass = Program.form1.PASS_TXT.Text;
- db = Program.form1.DB_TEXT.Text;
- string connectionString = "SERVER=" + server + ";" + "DATABASE=" + db + ";" + "UID=" + user + ";" + "PASSWORD=" + pass + ";";
- connection = new MySqlConnection(connectionString);
- }
- private bool OpenConnection()
- {
- try
- {
- connection.Open();
- return true;
- }
- catch (MySqlException ex)
- {
- switch (ex.Number)
- {
- case 0:
- MessageBox.Show("Cannot connect to server.");
- break;
- case 1045:
- MessageBox.Show("Invalid username/password.");
- break;
- }
- return false;
- }
- }
- private bool CloseConnection()
- {
- try
- {
- connection.Close();
- return true;
- }
- catch (MySqlException ex)
- {
- MessageBox.Show(ex.Message);
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement