private void ConfigureDataBase(string serverName, string userId, string password, string ApplicationPath) { try { SClass ClassS = new SClass(); if (ClassS.CheckMsSqlConnection(serverName, userId, password, ApplicationPath)) { ClassS.UpdateAppConfig("MsSqlServer", serverName); ClassS.UpdateAppConfig("MsSqlUserId", userId); ClassS.UpdateAppConfig("MsSqlPassword", password); ClassS.UpdateAppConfig("ApplicationPath", ApplicationPath); serverName = (ConfigurationManager.AppSettings["MsSqlServer"] == null || ConfigurationManager.AppSettings["MsSqlServer"].ToString() == string.Empty) ? null : ConfigurationManager.AppSettings["MsSqlServer"].ToString(); userId = (ConfigurationManager.AppSettings["MsSqlUserId"] == null || ConfigurationManager.AppSettings["MsSqlUserId"].ToString() == string.Empty) ? null : ConfigurationManager.AppSettings["MsSqlUserId"].ToString(); password = (ConfigurationManager.AppSettings["MsSqlPassword"] == null || ConfigurationManager.AppSettings["MsSqlPassword"].ToString() == string.Empty) ? null : ConfigurationManager.AppSettings["MsSqlPassword"].ToString(); ApplicationPath = (ConfigurationManager.AppSettings["ApplicationPath"] == null || ConfigurationManager.AppSettings["ApplicationPath"].ToString() == string.Empty) ? null : ConfigurationManager.AppSettings["ApplicationPath"].ToString(); if (ClassS.CheckMsSqlConnection(serverName, userId, password, ApplicationPath)) { Environment.ExitCode = 100; this.Close(); } else { Environment.ExitCode = 101; this.Close(); } } } catch (Exception) { } }
void bwDB_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker1 = sender as BackgroundWorker; worker1.ReportProgress((5)); if (rbtnLocalServer.Checked) { objTbl = new SClass().GetLocalInstance(); } else { objTbl = Microsoft.SqlServer.Management.Smo.SmoApplication.EnumAvailableSqlServers(); } worker1.ReportProgress((95)); }
/// <summary> /// Function for check the DataBase Connection /// </summary> /// <returns></returns> private bool CheckDataBase() { bool isTrue = false; string serverName = (ConfigurationManager.AppSettings["MsSqlServer"] == null || ConfigurationManager.AppSettings["MsSqlServer"].ToString() == string.Empty) ? null : ConfigurationManager.AppSettings["MsSqlServer"].ToString(); string userId = (ConfigurationManager.AppSettings["MsSqlUserId"] == null || ConfigurationManager.AppSettings["MsSqlUserId"].ToString() == string.Empty) ? null : ConfigurationManager.AppSettings["MsSqlUserId"].ToString(); string password = (ConfigurationManager.AppSettings["MsSqlPassword"] == null || ConfigurationManager.AppSettings["MsSqlPassword"].ToString() == string.Empty) ? null : ConfigurationManager.AppSettings["MsSqlPassword"].ToString(); string ApplicationPath = (ConfigurationManager.AppSettings["ApplicationPath"] == null || ConfigurationManager.AppSettings["ApplicationPath"].ToString() == string.Empty) ? null : ConfigurationManager.AppSettings["ApplicationPath"].ToString(); string isSqlServer = (ConfigurationManager.AppSettings["isServerConnection"] == null || ConfigurationManager.AppSettings["isServerConnection"].ToString() == string.Empty) ? null : ConfigurationManager.AppSettings["isServerConnection"].ToString(); SClass objDb = new SClass(); if (objDb.CheckMsSqlConnection(serverName, userId, password, ApplicationPath)) { isTrue = true; } else { isTrue = false; } return(isTrue); }
private void btnOkServer_Click(object sender, EventArgs e) { string server = cmbServers1.Text + @"\" + cmbInstance1.Text; string userId = textBox1.Text; string password = textBox2.Text; progressBar1.Visible = true; panel2.Enabled = false; Thread backgroundThread = new Thread( new ThreadStart(() => { SClass classS = new SClass(); if (!radioButton3.Checked) { cmbPath.DataSource = classS.GetOmPath(server, null, null); } else { cmbPath.DataSource = classS.GetOmPath(server, userId, password); } if (cmbPath.InvokeRequired) { cmbPath.BeginInvoke(new Action(() => cmbPath.DisplayMember = "location")); } try { progressBar1.BeginInvoke(new Action(() => progressBar1.Visible = false)); panel2.BeginInvoke(new Action(() => panel2.Enabled = true)); } catch (Exception) { } } )); backgroundThread.Start(); }