/[AnywhereTS-MSSQL]/trunk/TSAdminTool/Database.cs
ViewVC logotype

Diff of /trunk/TSAdminTool/Database.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/TSAdminTool/Database.cs	2012/07/15 05:13:20	134
+++ trunk/TSAdminTool/Database.cs	2012/07/15 05:58:56	135
@@ -320,14 +320,13 @@
                         {
                             try
                             {
-                                conn.Dispose();
+                                conn.CloseConnection(out ErrorInfo);
                                 using (MsSqlConnector conn1 = new MsSqlConnector(ProSupport.strDatabaseServer, ProSupport.strDatabaseInstance, "master"))
                                 {
                                     try
                                     {
                                         conn1.CreateConnection(out ErrorInfo);
                                         conn1.OpenConnection(out ErrorInfo);
-
                                         // create datagbase
                                         using (log4net.NDC.Push("CheckVersion().CreateDatabase"))
                                         {
@@ -382,85 +381,80 @@
                     }
                     catch (Exception ex)
                     {
-                        if (ErrorInfo == null)
+                        if (!ex.Message.ToLower().Contains(string.Format("invalid object name '{0}..AppInfo'", ATSGlobals.strDatabaseName).ToLower()))
                         {
-                            ErrorInfo = ex;
-                            using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
+                            if (ErrorInfo == null)
                             {
-                                Logging.DatabaseLog.Error(string.Format("Failed to get count of databases named: {0}{1}", System.Environment.NewLine, ATSGlobals.strDatabaseName));
+                                ErrorInfo = ex;
+                                using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ErrorInfo.GetType().Name, ErrorInfo.Message, System.Environment.NewLine, ErrorInfo.ToString())))
+                                {
+                                    Logging.DatabaseLog.Error(string.Format("Failed to get count of databases named: {0}{1}", System.Environment.NewLine, ATSGlobals.strDatabaseName));
+                                }
+                                throw ErrorInfo;
+                            }
+                            else
+                            {
+                                ErrorInfo = ex.GetBaseException();
+                                using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ErrorInfo.GetType().Name, ErrorInfo.Message, System.Environment.NewLine, ErrorInfo.ToString())))
+                                {
+                                    Logging.DatabaseLog.Error(string.Format("Failed to get count of databases named: {0}{1}", System.Environment.NewLine, ATSGlobals.strDatabaseName));
+                                }
+                                throw ErrorInfo;
+                            }
+                        }
+                        try
+                        {                            
+                            conn.CloseConnection(out ErrorInfo);
+                            ErrorInfo = null; // reset ErrorInfo
+                            using (MsSqlConnector conn1 = new MsSqlConnector(ProSupport.strDatabaseServer, ProSupport.strDatabaseInstance, "master"))
+                            {
+                                try
+                                {
+                                    conn1.CreateConnection(out ErrorInfo);
+                                    conn1.OpenConnection(out ErrorInfo);
+                                    using (log4net.NDC.Push("CheckVersion().CreateTables"))
+                                    {
+                                        // create tables
+                                        Logging.DatabaseLog.Info(string.Format("Creating Tables in {0} Database", ATSGlobals.strDatabaseName));
+                                        RunScript(SQLServerResources.CreateTables, conn1, out ErrorInfo);
+                                        Logging.DatabaseLog.Info(string.Format("Created Tables in {0} Database", ATSGlobals.strDatabaseName));
+                                    }
+                                }
+                                catch (Exception ex1)
+                                {
+                                    if (ErrorInfo == null) { ErrorInfo = new Exception(ex1.Message, ex); }
+                                    throw ErrorInfo;
+                                }         
                             }
-                            throw ErrorInfo;
                         }
-                        else
+                        catch (Exception ex1)
                         {
-                            ErrorInfo = ex.GetBaseException();
-                            using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ErrorInfo.GetType().Name, ErrorInfo.Message, System.Environment.NewLine, ErrorInfo.ToString())))
+                            if (ErrorInfo == null)
                             {
-                                Logging.DatabaseLog.Error(string.Format("Failed to get count of databases named: {0}{1}", System.Environment.NewLine, ATSGlobals.strDatabaseName));
+                                ErrorInfo = ex1;
+                                using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
+                                {
+                                    Logging.DatabaseLog.Error(string.Format("Failed to get count of databases named: {0}{1}", System.Environment.NewLine, ATSGlobals.strDatabaseName));
+                                }
+                                throw ErrorInfo;
+                            }
+                            else
+                            {
+                                ErrorInfo = ex1.GetBaseException();
+                                using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ErrorInfo.GetType().Name, ErrorInfo.Message, System.Environment.NewLine, ErrorInfo.ToString())))
+                                {
+                                    Logging.DatabaseLog.Error(string.Format("Failed to get count of databases named: {0}{1}", System.Environment.NewLine, ATSGlobals.strDatabaseName));
+                                }
+                                throw ErrorInfo;
                             }
-                            throw ErrorInfo;
                         }
+                        if (ErrorInfo == null)
+                            ErrorInfo = ex;
+                        throw ErrorInfo;
                     }
                 }
                 #endregion
 
-                #region old-code might still need
-                //try
-                //{
-                //    //using (log4net.NDC.Push(string.Format("SQL Statment={0}", "SELECT value from {0}..AppInfo where property='version'", ATSGlobals.strDatabaseName)))
-                //    //{
-                //        Logging.DatabaseLog.Debug(string.Format("Getting {0} Database Version#1", ATSGlobals.strDatabaseName));
-                //        sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace(ATSGlobals.strDatabaseName, "master"));
-                //        if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
-                //        sqlCmd = new SqlCommand(string.Format("SELECT value from {0}..AppInfo where property='version'",ATSGlobals.strDatabaseName), sqlCon);
-                //        strResult = (string)sqlCmd.ExecuteScalar();
-                //        sqlCon.Close();
-                //    //}
-                //    Logging.DatabaseLog.DebugFormat("{0} database version={1}",ATSGlobals.strDatabaseName, strResult);
-                //}
-                //catch(SqlException ex)
-                //{
-                //    // the database exists, but one or more tables are missing
-                //    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())))
-                //    {
-                //        Logging.DatabaseLog.Error("Failed to get database version");
-                //    }
-                //    try
-                //    {
-                //        //using (log4net.NDC.Push(string.Format("SQL Statment={0}", SQLServerResources.CreateTables)))
-                //        //{
-                //            Logging.DatabaseLog.Debug(string.Format("Creating Tables in {0} Database in CheckVersion()", ATSGlobals.strDatabaseName));
-                //            sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace(ATSGlobals.strDatabaseName, "master"));
-                //            if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
-                //            RunScript(SQLServerResources.CreateTables);
-                //            sqlCon.Close();
-                //        //}
-                //        Logging.DatabaseLog.Debug(string.Format("Created Tables in {0} Database in CheckVersion()", ATSGlobals.strDatabaseName));
-                //        using (log4net.NDC.Push(string.Format("SQL Statment={0}", string.Format("SELECT value from {0}..AppInfo where property='version'", ATSGlobals.strDatabaseName))))
-                //        {
-                //            Logging.DatabaseLog.Debug(string.Format("Getting {0} Database Version#2", ATSGlobals.strDatabaseName));
-                //            sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace(ATSGlobals.strDatabaseName, "master"));
-                //            if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
-                //            sqlCmd = new SqlCommand(string.Format("SELECT value from {0}..AppInfo where property='version'", ATSGlobals.strDatabaseName), sqlCon);
-                //            strResult = (string)sqlCmd.ExecuteScalar();
-                //            sqlCon.Close();
-                //        }
-                //        Logging.DatabaseLog.DebugFormat("{0} database version={1}",ATSGlobals.strDatabaseName, strResult);
-                //    }
-                //    catch(SqlException ex1)
-                //    {
-                //        using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", ex1.Number.ToString(), ex1.Message, System.Environment.NewLine, ex1.ToString())))
-                //        {
-                //            Logging.DatabaseLog.Error("Failed to get database version");
-                //        }
-                //        return (int)VersionCheck.Failed;
-                //    }
-                //}
-                #endregion
-
-
-                //sqlCon.Close();
-
                 if (vDb == v)
                     return (int)VersionCheck.Equal;
 

 

  ViewVC Help
Powered by ViewVC 1.1.22