/[AnywhereTS-MSSQL]/trunk/TSControlPanel/frmConfigureControlPanel.cs
ViewVC logotype

Diff of /trunk/TSControlPanel/frmConfigureControlPanel.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/TSControlPanel/frmConfigureControlPanel.cs	2012/07/13 22:58:13	90
+++ trunk/TSControlPanel/frmConfigureControlPanel.cs	2012/07/14 00:36:23	91
@@ -6,6 +6,7 @@
 using System.Text;
 using System.Windows.Forms;
 using System.Data.SqlClient;
+using AnywhereTS.DBSupport;
 
 namespace AnywhereTS
 {
@@ -22,30 +23,42 @@
             string dataServer;
             dataServer = textInput.Text.Trim();
             //Create a connection to SQL Server
-            SqlConnection sqlCon = new SqlConnection();
-            try
+            Exception ErrorInfo = null;
+            Logging.ATSAdminLog.Debug("frmConfigureControlPanel.btnOk_Click() called ");
+            using (MsSqlConnector conn = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, "master"))
             {
-                sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
-                sqlCon.Open();
-            }
-            catch (SqlException sql_ex)
-            {
-                MessageBox.Show("Could not connect to the datbase server. Please check your spelling and your connections. SQL Server error:\n" + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString());
-                using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", sql_ex.Number.ToString(), sql_ex.Message, System.Environment.NewLine, sql_ex.ToString())))
+                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("ConnectionString={0}", Properties.Settings.Default.atsConnectionString)))
+                    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.TSControlPanelLog.Error("Could not connect to the datbase server");
+                        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;
                 }
-                return;
             }
-
-
+            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.strDatabaseServer = textInput.Text;
-            ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, ProSupport.strDatabaseServer);
-
+            ProSupport.strAnywhereTSServer = textInput.Text;
+            ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, ProSupport.strAnywhereTSServer);
             DialogResult = DialogResult.OK; //return
         }
     }

 

  ViewVC Help
Powered by ViewVC 1.1.22