/[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/16 17:22:04	205
+++ trunk/TSControlPanel/frmConfigureControlPanel.cs	2012/07/16 18:03:31	206
@@ -7,6 +7,7 @@
 using System.Windows.Forms;
 using System.Data.SqlClient;
 using AnywhereTS.DBSupport;
+using Microsoft.Win32;
 
 namespace AnywhereTS
 {
@@ -17,11 +18,46 @@
             InitializeComponent();
         }
 
+
+        private void GetAnywhereTSDatabase(string ATSServer, out string DBServer, out string DBInstance)
+        {
+            DBServer = string.Empty;
+            DBInstance = string.Empty;
+            try
+            {
+                Logging.DatabaseLog.InfoFormat("Getting AnywhereTS Database Server and Instance from: {0}", ATSServer);
+                RegistryKey rk = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, ATSServer);
+                rk = rk.OpenSubKey(string.Format(@"SOFTWARE\{0}\ts-config", ATSGlobals.ApplicationName));
+                DBServer = (string)rk.GetValue(ProSupport.strRegDatabaseServer);
+                DBInstance = (string)rk.GetValue(ProSupport.strRegDatabaseInstance);
+                Logging.DatabaseLog.DebugFormat("DBServer={0} DBInstance={1}", DBServer, DBInstance);
+                Logging.DatabaseLog.InfoFormat("Successfully retreived AnywhereTS Database Server and Instance from: {0}", ATSServer);
+            }
+            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));
+                }
+            }
+
+        }
+
         private void btnOk_Click(object sender, EventArgs e)
         {
             // Validate database server
             string dataServer;
             dataServer = textInput.Text.Trim();
+
+            string DBServer = "";
+            string DBInstance = "";
+
+            GetAnywhereTSDatabase(dataServer, out DBServer, out DBInstance);
+            ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, DBServer);
+            ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, DBInstance);
+            ProSupport.strDatabaseServer = DBServer;
+            ProSupport.strDatabaseInstance = DBInstance;
+
             //Create a connection to SQL Server
             Exception ErrorInfo = null;
             Logging.ATSAdminLog.Debug("frmConfigureControlPanel.btnOk_Click() called ");
@@ -29,13 +65,9 @@
             {
                 try
                 {
+                    Logging.ATSAdminLog.Info(string.Format("Opening Database {0}", ATSGlobals.strDatabaseName));
                     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)
@@ -57,7 +89,7 @@
             }
             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;
+            ProSupport.strAnywhereTSServer = dataServer;
             ATSGlobals.SetATSRegValue(ProSupport.strRegAnywhereTSServer, ProSupport.strAnywhereTSServer);
             DialogResult = DialogResult.OK; //return
         }

 

  ViewVC Help
Powered by ViewVC 1.1.22