7 |
using System.Windows.Forms; |
using System.Windows.Forms; |
8 |
using System.Data.SqlClient; |
using System.Data.SqlClient; |
9 |
using AnywhereTS.DBSupport; |
using AnywhereTS.DBSupport; |
10 |
|
using Microsoft.Win32; |
11 |
|
|
12 |
namespace AnywhereTS |
namespace AnywhereTS |
13 |
{ |
{ |
18 |
InitializeComponent(); |
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) |
private void btnOk_Click(object sender, EventArgs e) |
47 |
{ |
{ |
48 |
// Validate database server |
// Validate database server |
49 |
string dataServer; |
string dataServer; |
50 |
dataServer = textInput.Text.Trim(); |
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 |
//Create a connection to SQL Server |
62 |
Exception ErrorInfo = null; |
Exception ErrorInfo = null; |
63 |
Logging.ATSAdminLog.Debug("frmConfigureControlPanel.btnOk_Click() called "); |
Logging.ATSAdminLog.Debug("frmConfigureControlPanel.btnOk_Click() called "); |
65 |
{ |
{ |
66 |
try |
try |
67 |
{ |
{ |
68 |
|
Logging.ATSAdminLog.Info(string.Format("Opening Database {0}", ATSGlobals.strDatabaseName)); |
69 |
conn.CreateConnection(out ErrorInfo); |
conn.CreateConnection(out ErrorInfo); |
70 |
conn.OpenConnection(out ErrorInfo); |
conn.OpenConnection(out ErrorInfo); |
|
|
|
|
// create datagbase |
|
|
Logging.ATSAdminLog.Info(string.Format("Opening Database {0}", ATSGlobals.strDatabaseName)); |
|
|
|
|
|
|
|
71 |
Logging.ATSAdminLog.Info(string.Format("Opened Database {0}", ATSGlobals.strDatabaseName)); |
Logging.ATSAdminLog.Info(string.Format("Opened Database {0}", ATSGlobals.strDatabaseName)); |
72 |
} |
} |
73 |
catch (SqlException ex) |
catch (SqlException ex) |
89 |
} |
} |
90 |
if (ErrorInfo != null) { MessageBox.Show(string.Format("Failed to open database {0}. Please check the log for errors.", ATSGlobals.strDatabaseName)); } |
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 |
// Save database server to variable and registry |
92 |
ProSupport.strAnywhereTSServer = textInput.Text; |
ProSupport.strAnywhereTSServer = dataServer; |
93 |
ATSGlobals.SetATSRegValue(ProSupport.strRegAnywhereTSServer, ProSupport.strAnywhereTSServer); |
ATSGlobals.SetATSRegValue(ProSupport.strRegAnywhereTSServer, ProSupport.strAnywhereTSServer); |
94 |
DialogResult = DialogResult.OK; //return |
DialogResult = DialogResult.OK; //return |
95 |
} |
} |