Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DBConnect
- {
- private MySqlConnection connection;
- private string server;
- private string database;
- private string uid;
- private string password;
- //Constructor
- public DBConnect()
- {
- Initialize();
- }
- //Initialize values
- private void Initialize()
- {
- server = "localhost:3306";
- database = "cirkuit_db";
- uid = "root";
- password = "";
- string connectionString;
- connectionString = "SERVER=" + server + ";" + "DATABASE=" +
- database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
- connection = new MySqlConnection(connectionString);
- }
- //open connection to database
- public int OpenConnection()
- {
- int resp = 0; //0 si se pudo conectar
- try
- {
- connection.Open();
- resp = 1;
- }
- catch (MySqlException ex)
- {
- //When handling errors, you can your application's response based
- //on the error number.
- //The two most common error numbers when connecting are as follows:
- //0: Cannot connect to server.
- //1045: Invalid user name and/or password.
- switch (ex.Number)
- {
- case 0:
- resp = 2; //no se puede conectar al servidor. contacte al administrador
- break;
- case 1045:
- resp = 1045; // 1045 usuario o password invalido.. por favor trate otravez
- break;
- }
- }
- return resp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement