ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/AnywhereTS-MSSQL/trunk/TSAdminTool/Database.cs
(Generate patch)

Comparing trunk/TSAdminTool/Database.cs (file contents):
Revision 38 by william, Thu Jul 12 11:35:07 2012 UTC vs.
Revision 39 by william, Thu Jul 12 12:21:43 2012 UTC

# Line 27 | Line 27 | namespace AnywhereTS
27          private SqlCommand sqlCmd = new SqlCommand();
28  
29          const string SQL_BROWSER_SERVICE_NAME = "SQLBrowser";
30 <
30 >        const Version CURRENT_DB_VERSION = new Version(1, 0, 0, 3);
31          public static string InstanceName
32          {
33              get
# Line 52 | Line 52 | namespace AnywhereTS
52              
53              Logging.ATSAdminLog.Debug("SetupDatabase() called ");
54              try
55 <            {
56 <                sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString;
55 >            {                
56 >                sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString;                
57 >                using (log4net.NDC.Push(string.Format("ConnectionString={0}", Properties.Settings.Default.atsConnectionString)))
58 >                {
59 >                    Logging.ATSAdminLog.Debug("Opening connection to AnywhereTS Database");
60 >                }
61                  sqlCon.Open();
62              }
63              catch
# Line 63 | Line 67 | namespace AnywhereTS
67                  //bCreateDB = true;
68                  try
69                  {
70 <                    sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
71 <                    sqlCon.Open();
72 <                    RunScript(Resource1.CreateDatabase.ToString());
73 <                    sqlCon.Close();
74 <                    sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
75 <                    sqlCon.Open();
76 <                    RunScript(Resource1.CreateTables.ToString());
77 <                    sqlCon.Close();
78 <                    //sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString);
79 <                    //sqlCon.Open();
70 >                    using (log4net.NDC.Push(string.Format("SQL Statment={0}", Resource1.CreateDatabase.ToString())))
71 >                    {
72 >                        Logging.ATSAdminLog.Debug("Creating Database AnywhereTS");
73 >                        sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
74 >                        sqlCon.Open();
75 >                        RunScript(Resource1.CreateDatabase.ToString());
76 >                        sqlCon.Close();
77 >                    }
78 >                    Logging.ATSAdminLog.Debug("Created Database AnywhereTS");
79 >
80 >                    using (log4net.NDC.Push(string.Format("SQL Statment={0}", Resource1.CreateTables.ToString())))
81 >                    {
82 >                        Logging.ATSAdminLog.Debug("Creating Tables in AnywhereTS Database");
83 >                        sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
84 >                        sqlCon.Open();
85 >                        RunScript(Resource1.CreateTables.ToString());
86 >                        sqlCon.Close();
87 >                    }
88 >                    Logging.ATSAdminLog.Debug("Created Tables in AnywhereTS Database");
89                  }
90                  catch (SqlException sql_ex1)
91                  {
92                      SqlException sql_ex = (sql_ex1.GetBaseException() as SqlException);
93                      MessageBox.Show(string.Format("Failed to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString());
94 +
95 +                    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())))
96 +                    {
97 +                        Logging.ATSAdminLog.Error("Failed to open connection to AnywhereTS Database");
98 +                    }
99                      return bContinue;
100                  }
101              }
# Line 86 | Line 104 | namespace AnywhereTS
104              Version databaseVersion; // The current version of the database
105              int chkVer = CheckVersion(out databaseVersion);
106              VersionCheck verChk = (VersionCheck)chkVer;
107 <            MessageBox.Show(string.Format("Version Check: {0} Version: {1}", verChk.ToString(), databaseVersion.ToString()));
107 >            //MessageBox.Show(string.Format("Version Check: {0} Version: {1}", verChk.ToString(), databaseVersion.ToString()));
108 >            Logging.ATSAdminLog.DebugFormat("Version Check: {0} Version: {1}", verChk.ToString(), databaseVersion.ToString());
109              switch (chkVer)
110              {
111                  case (int)VersionCheck.Equal:
# Line 106 | Line 125 | namespace AnywhereTS
125                              // Run the apropriate upgdrade script(s)
126                              case "1.0.0.0":
127                                  {   // Current database is version 1.0.0.0, update to 1.0.0.1
128 +                                    Logging.ATSAdminLog.DebugFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.0", "1.0.0.1");
129                                      bContinue = RunScript(Resource1.UpdateDatabase1.ToString());
130 +                                    Logging.ATSAdminLog.DebugFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.0", "1.0.0.1");
131                                      goto case "1.0.0.1"; // Continue and upgrade one more step
132                                  }
133                              case "1.0.0.1":
134                                  {   // Current database is version 1.0.0.1, update to 1.0.0.2
135 +                                    Logging.ATSAdminLog.DebugFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.1", "1.0.0.2");
136                                      bContinue = RunScript(Resource1.UpdateDatabase2.ToString());
137 +                                    Logging.ATSAdminLog.DebugFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.2");
138                                      goto case "1.0.0.2"; // Continue and upgrade one more step
139                                  }
140                              case "1.0.0.2":
141                                  {   // Current database is version 1.0.0.2, update to 1.0.0.3
142 +                                    Logging.ATSAdminLog.DebugFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.3");
143                                      bContinue = RunScript(Resource1.UpdateDatabase3.ToString());
144 +                                    Logging.ATSAdminLog.DebugFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.3");
145                                      break;
146                                  }
147  
# Line 124 | Line 149 | namespace AnywhereTS
149                              default:
150                                  {
151                                      MessageBox.Show("Error: Not able to upgrade database (51188)");
152 +                                    Logging.ATSAdminLog.DebugFormat("Failed to upgrade Database from version: {0} to version: {1}", databaseVersion.ToString(), CURRENT_DB_VERSION.ToString());
153                                      break;
154                                  }
155                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines