Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using MySql.Data.MySqlClient;
- using System.Windows.Forms;
- namespace CourseProject
- {
- class Db
- {
- public static MySqlConnection connection = new MySqlConnection("SERVER=192.168.0.163;DATABASE=tsp2;UID=tsp;PASSWORD=123;");
- public static 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;
- }
- }
- public static 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