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

Contents of /trunk/TSControlPanel/frmConfigureControlPanel.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 206 - (show annotations) (download)
Mon Jul 16 18:03:31 2012 UTC (7 years, 7 months ago) by william
File size: 4665 byte(s)
+ fix issue where:
1) you install TSControlPanel on a system that does not have ATSAdmin installed
2) you do not have a DBServer or DBInstance setting in the registry
** fixed by using the entered ATSServer name, and retrieving the values using remote registry access

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.Data.SqlClient;
9 using AnywhereTS.DBSupport;
10 using Microsoft.Win32;
11
12 namespace AnywhereTS
13 {
14 public partial class frmConfigureControlPanel : Form
15 {
16 public frmConfigureControlPanel()
17 {
18 InitializeComponent();
19 }
20
21
22 private void GetAnywhereTSDatabase(string ATSServer, out string DBServer, out string DBInstance)
23 {
24 DBServer = string.Empty;
25 DBInstance = string.Empty;
26 try
27 {
28 Logging.DatabaseLog.InfoFormat("Getting AnywhereTS Database Server and Instance from: {0}", ATSServer);
29 RegistryKey rk = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, ATSServer);
30 rk = rk.OpenSubKey(string.Format(@"SOFTWARE\{0}\ts-config", ATSGlobals.ApplicationName));
31 DBServer = (string)rk.GetValue(ProSupport.strRegDatabaseServer);
32 DBInstance = (string)rk.GetValue(ProSupport.strRegDatabaseInstance);
33 Logging.DatabaseLog.DebugFormat("DBServer={0} DBInstance={1}", DBServer, DBInstance);
34 Logging.DatabaseLog.InfoFormat("Successfully retreived AnywhereTS Database Server and Instance from: {0}", ATSServer);
35 }
36 catch (Exception ex)
37 {
38 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
39 {
40 Logging.DatabaseLog.Error(string.Format("Failed to open Database {0}", ATSGlobals.strDatabaseName));
41 }
42 }
43
44 }
45
46 private void btnOk_Click(object sender, EventArgs e)
47 {
48 // Validate database server
49 string dataServer;
50 dataServer = textInput.Text.Trim();
51
52 string DBServer = "";
53 string DBInstance = "";
54
55 GetAnywhereTSDatabase(dataServer, out DBServer, out DBInstance);
56 ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, DBServer);
57 ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, DBInstance);
58 ProSupport.strDatabaseServer = DBServer;
59 ProSupport.strDatabaseInstance = DBInstance;
60
61 //Create a connection to SQL Server
62 Exception ErrorInfo = null;
63 Logging.ATSAdminLog.Debug("frmConfigureControlPanel.btnOk_Click() called ");
64 using (MsSqlConnector conn = new MsSqlConnector(ProSupport.strDatabaseServer, ProSupport.strDatabaseInstance, "master"))
65 {
66 try
67 {
68 Logging.ATSAdminLog.Info(string.Format("Opening Database {0}", ATSGlobals.strDatabaseName));
69 conn.CreateConnection(out ErrorInfo);
70 conn.OpenConnection(out ErrorInfo);
71 Logging.ATSAdminLog.Info(string.Format("Opened Database {0}", ATSGlobals.strDatabaseName));
72 }
73 catch (SqlException ex)
74 {
75 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())))
76 {
77 Logging.DatabaseLog.Error(string.Format("Failed to open Database {0}", ATSGlobals.strDatabaseName));
78 }
79 ErrorInfo = ex; throw ErrorInfo;
80 }
81 catch (Exception ex)
82 {
83 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
84 {
85 Logging.DatabaseLog.Error(string.Format("Failed to open Database {0}", ATSGlobals.strDatabaseName));
86 }
87 ErrorInfo = ex; throw ErrorInfo;
88 }
89 }
90 if (ErrorInfo != null) { MessageBox.Show(string.Format("Failed to open database {0}. Please check the log for errors.", ATSGlobals.strDatabaseName)); }
91 // Save database server to variable and registry
92 ProSupport.strAnywhereTSServer = dataServer;
93 ATSGlobals.SetATSRegValue(ProSupport.strRegAnywhereTSServer, ProSupport.strAnywhereTSServer);
94 DialogResult = DialogResult.OK; //return
95 }
96 }
97 }

  ViewVC Help
Powered by ViewVC 1.1.22