Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. class DatabaseConnection
  2.     {
  3.         //database stuff
  4.         private const String SERVER = "127.0.0.1";
  5.         private const String DATABASE = "hospital_database";
  6.         private const String UID = "root";
  7.         private const String PASSWORD = "root";
  8.         private static MySqlConnection dbConn;
  9.  
  10.         public static void InitializeDB()
  11.         {
  12.             MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
  13.             builder.Server = SERVER;
  14.             builder.UserID = UID;
  15.             builder.Password = PASSWORD;
  16.             builder.Database = DATABASE;
  17.  
  18.             String connString = builder.ToString();
  19.  
  20.             builder = null;
  21.  
  22.             Console.WriteLine(connString);
  23.  
  24.             dbConn = new MySqlConnection(connString);
  25.  
  26.             Application.ApplicationExit += (sender, args) => {
  27.                 if (dbConn != null)
  28.                 {
  29.                     dbConn.Dispose();
  30.                     dbConn = null;
  31.                 }
  32.             };
  33.  
  34.             MySqlCommand cmd = new MySqlCommand(query, dbConn);
  35.  
  36.          
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement