6 |
|
using System.Text; |
7 |
|
using System.Windows.Forms; |
8 |
|
using System.Data.SqlClient; |
9 |
+ |
using AnywhereTS.DBSupport; |
10 |
|
|
11 |
|
namespace AnywhereTS |
12 |
|
{ |
23 |
|
string dataServer; |
24 |
|
dataServer = textInput.Text.Trim(); |
25 |
|
//Create a connection to SQL Server |
26 |
< |
SqlConnection sqlCon = new SqlConnection(); |
27 |
< |
try |
26 |
> |
Exception ErrorInfo = null; |
27 |
> |
Logging.ATSAdminLog.Debug("frmConfigureControlPanel.btnOk_Click() called "); |
28 |
> |
using (MsSqlConnector conn = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, "master")) |
29 |
|
{ |
30 |
< |
sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master")); |
31 |
< |
sqlCon.Open(); |
32 |
< |
} |
33 |
< |
catch (SqlException sql_ex) |
34 |
< |
{ |
35 |
< |
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()); |
36 |
< |
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()))) |
30 |
> |
try |
31 |
> |
{ |
32 |
> |
conn.CreateConnection(out ErrorInfo); |
33 |
> |
conn.OpenConnection(out ErrorInfo); |
34 |
> |
|
35 |
> |
// create datagbase |
36 |
> |
Logging.ATSAdminLog.Info(string.Format("Opening Database {0}", ATSGlobals.strDatabaseName)); |
37 |
> |
|
38 |
> |
|
39 |
> |
Logging.ATSAdminLog.Info(string.Format("Opened Database {0}", ATSGlobals.strDatabaseName)); |
40 |
> |
} |
41 |
> |
catch (SqlException ex) |
42 |
|
{ |
43 |
< |
using (log4net.NDC.Push(string.Format("ConnectionString={0}", Properties.Settings.Default.atsConnectionString))) |
43 |
> |
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()))) |
44 |
|
{ |
45 |
< |
Logging.TSControlPanelLog.Error("Could not connect to the datbase server"); |
45 |
> |
Logging.DatabaseLog.Error(string.Format("Failed to open Database {0}", ATSGlobals.strDatabaseName)); |
46 |
|
} |
47 |
+ |
ErrorInfo = ex; throw ErrorInfo; |
48 |
+ |
} |
49 |
+ |
catch (Exception ex) |
50 |
+ |
{ |
51 |
+ |
using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString()))) |
52 |
+ |
{ |
53 |
+ |
Logging.DatabaseLog.Error(string.Format("Failed to open Database {0}", ATSGlobals.strDatabaseName)); |
54 |
+ |
} |
55 |
+ |
ErrorInfo = ex; throw ErrorInfo; |
56 |
|
} |
41 |
– |
return; |
57 |
|
} |
58 |
< |
|
44 |
< |
|
58 |
> |
if (ErrorInfo != null) { MessageBox.Show(string.Format("Failed to open database {0}. Please check the log for errors.", ATSGlobals.strDatabaseName)); } |
59 |
|
// Save database server to variable and registry |
60 |
< |
ProSupport.strDatabaseServer = textInput.Text; |
61 |
< |
ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, ProSupport.strDatabaseServer); |
48 |
< |
|
60 |
> |
ProSupport.strAnywhereTSServer = textInput.Text; |
61 |
> |
ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, ProSupport.strAnywhereTSServer); |
62 |
|
DialogResult = DialogResult.OK; //return |
63 |
|
} |
64 |
|
} |