using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using AnywhereTS.DBSupport; namespace AnywhereTS { public partial class frmConfigureControlPanel : Form { public frmConfigureControlPanel() { InitializeComponent(); } private void btnOk_Click(object sender, EventArgs e) { // Validate database server string dataServer; dataServer = textInput.Text.Trim(); //Create a connection to SQL Server Exception ErrorInfo = null; Logging.ATSAdminLog.Debug("frmConfigureControlPanel.btnOk_Click() called "); using (MsSqlConnector conn = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, "master")) { try { conn.CreateConnection(out ErrorInfo); conn.OpenConnection(out ErrorInfo); // create datagbase Logging.ATSAdminLog.Info(string.Format("Opening Database {0}", ATSGlobals.strDatabaseName)); Logging.ATSAdminLog.Info(string.Format("Opened Database {0}", ATSGlobals.strDatabaseName)); } catch (SqlException ex) { using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", ex.Number.ToString(), ex.Message, System.Environment.NewLine, ex.ToString()))) { Logging.DatabaseLog.Error(string.Format("Failed to open Database {0}", ATSGlobals.strDatabaseName)); } ErrorInfo = ex; throw ErrorInfo; } catch (Exception ex) { using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString()))) { Logging.DatabaseLog.Error(string.Format("Failed to open Database {0}", ATSGlobals.strDatabaseName)); } ErrorInfo = ex; throw ErrorInfo; } } if (ErrorInfo != null) { MessageBox.Show(string.Format("Failed to open database {0}. Please check the log for errors.", ATSGlobals.strDatabaseName)); } // Save database server to variable and registry ProSupport.strAnywhereTSServer = textInput.Text; ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, ProSupport.strAnywhereTSServer); DialogResult = DialogResult.OK; //return } } }