1 |
william |
4 |
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 |
william |
91 |
using AnywhereTS.DBSupport; |
10 |
william |
206 |
using Microsoft.Win32; |
11 |
william |
4 |
|
12 |
|
|
namespace AnywhereTS |
13 |
|
|
{ |
14 |
|
|
public partial class frmConfigureControlPanel : Form |
15 |
|
|
{ |
16 |
|
|
public frmConfigureControlPanel() |
17 |
|
|
{ |
18 |
|
|
InitializeComponent(); |
19 |
|
|
} |
20 |
|
|
|
21 |
william |
206 |
|
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 |
william |
4 |
private void btnOk_Click(object sender, EventArgs e) |
47 |
|
|
{ |
48 |
|
|
// Validate database server |
49 |
|
|
string dataServer; |
50 |
|
|
dataServer = textInput.Text.Trim(); |
51 |
william |
206 |
|
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 |
william |
4 |
//Create a connection to SQL Server |
62 |
william |
91 |
Exception ErrorInfo = null; |
63 |
|
|
Logging.ATSAdminLog.Debug("frmConfigureControlPanel.btnOk_Click() called "); |
64 |
william |
92 |
using (MsSqlConnector conn = new MsSqlConnector(ProSupport.strDatabaseServer, ProSupport.strDatabaseInstance, "master")) |
65 |
william |
4 |
{ |
66 |
william |
91 |
try |
67 |
william |
46 |
{ |
68 |
william |
206 |
Logging.ATSAdminLog.Info(string.Format("Opening Database {0}", ATSGlobals.strDatabaseName)); |
69 |
william |
91 |
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 |
william |
49 |
{ |
77 |
william |
91 |
Logging.DatabaseLog.Error(string.Format("Failed to open Database {0}", ATSGlobals.strDatabaseName)); |
78 |
william |
49 |
} |
79 |
william |
91 |
ErrorInfo = ex; throw ErrorInfo; |
80 |
william |
46 |
} |
81 |
william |
91 |
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 |
william |
4 |
} |
90 |
william |
91 |
if (ErrorInfo != null) { MessageBox.Show(string.Format("Failed to open database {0}. Please check the log for errors.", ATSGlobals.strDatabaseName)); } |
91 |
william |
4 |
// Save database server to variable and registry |
92 |
william |
206 |
ProSupport.strAnywhereTSServer = dataServer; |
93 |
william |
92 |
ATSGlobals.SetATSRegValue(ProSupport.strRegAnywhereTSServer, ProSupport.strAnywhereTSServer); |
94 |
william |
4 |
DialogResult = DialogResult.OK; //return |
95 |
|
|
} |
96 |
|
|
} |
97 |
|
|
} |