/// <summary> /// Initializes the DBHelper based on information stored in the ConfigMan object using the sql engine enumerated by DbConType /// </summary> /// <param name="configManager"></param> /// <param name="type"></param> public DBHelper(ConfigManager configManager, DbConType type = DbConType.MsSQL) { configMan = configManager; connType = type; switch (type) { default: goto case DbConType.MsSQL; case DbConType.MySQL: mySQL_conn = new MySqlConnection(ConnectionString); mySQL_cmd = new MySqlCommand() { Connection = mySQL_conn }; break; case DbConType.MsSQL: msSQL_conn = new SqlConnection(ConnectionString); msSQL_cmd = new SqlCommand() { Connection = msSQL_conn }; break; } }
/// <summary> /// Initializes the DBHelper based on information stored in the ConfigMan object using the sql engine enumerated by DbConType /// </summary> /// <param name="configManager"></param> /// <param name="type"></param> public DBHelper(ConfigMan configManager, DbConType type) { configMan = configManager; string ip = configMan["IP"]; string name = configMan["WorldName"]; string user = configMan["WorldUser"]; string pass = configMan["WorldPass"]; bool trusted = configMan["Trusted", "DB"]; switch (type) { default: goto case DbConType.MsSQL; case DbConType.MySQL: mySQL_conn = new MySqlConnection($"server={ip};database={name};user={user};password={pass}"); mySQL_cmd = new MySqlCommand() { Connection = mySQL_conn }; break; case DbConType.MsSQL: string connStr = $"Server={ip};Database={name};"; if (trusted) { connStr += "Trusted_Connection=true;"; } else { connStr += $"User ID={user};Password={pass}"; } msSQL_conn = new SqlConnection(connStr); msSQL_cmd = new SqlCommand() { Connection = msSQL_conn }; break; } }
void configureDB() { DbConType sqlEngine = (DbConType)confMgr["Engine", "DB"]; db = new DBHelper(confMgr, sqlEngine); db.ProgressMaxSet += (o, x) => { progressBar.Maximum = x.Maximum; //if (x.Message != null) //s_status_lb.Text = x.Message; }; db.ProgressValueSet += (o, x) => { progressBar.Value = x.Value; //if (x.Message != null) //ts_status_lb.Text = x.Message; }; db.ProgressReset += (o, x) => { progressBar.Maximum = 100; progressBar.Value = 0; //ts_status_lb.Text = string.Empty; }; db.Message += (o, x) => progressBar.Text = x.Message; db.Error += (o, x) => { MessageBox.Show(x.Message, "SQL Error", MessageBoxButtons.OK, MessageBoxIcon.Error); logMgr.Enter(Sender.RDB, Level.NOTICE, x.Message); }; }