/[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/14 03:14:54	98
+++ trunk/TSAdminTool/Database.cs	2012/07/14 04:50:27	99
@@ -25,171 +25,168 @@
             DatabaseCreated,
         };
 
-        private SqlConnection sqlCon = new SqlConnection();
-        private SqlCommand sqlCmd = new SqlCommand();
+        //private SqlConnection sqlCon = new SqlConnection();
+        //private SqlCommand sqlCmd = new SqlCommand();
 
         const string SQL_BROWSER_SERVICE_NAME = "SQLBrowser";
-        public static string InstanceName { get { return Properties.Settings.Default.DBInstance; } }
+        public static string InstanceName { get { return AnywhereTS.DBSupport.Properties.Settings.Default.DBInstance; } }
         public bool SetupDatabase()
         {
             Exception ErrorInfo = null;
             bool bContinue = false;
             // Create a connection to SQL Server
             Logging.ATSAdminLog.Debug("SetupDatabase() called ");
-            ProSupport.strDatabaseServer = Properties.Settings.Default.DBServer;
-            ProSupport.strDatabaseInstance = Properties.Settings.Default.DBInstance;
+            ProSupport.strDatabaseServer = AnywhereTS.DBSupport.Properties.Settings.Default.DBServer;
+            ProSupport.strDatabaseInstance = AnywhereTS.DBSupport.Properties.Settings.Default.DBInstance;
 
             ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseServer, ProSupport.strDatabaseServer);
-            ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, ProSupport.strRegDatabaseInstance);
+            ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseInstance, ProSupport.strDatabaseInstance);
 
-           
-            #region Database Creation support
-            using (MsSqlConnector conn = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, ATSGlobals.strDatabaseName))
-            {
-                try
-                {
-                    conn.CreateConnection(out ErrorInfo);
-                    conn.OpenConnection(out ErrorInfo);
-                }
-                catch (Exception ex) 
-                {
-                    try
-                    {
-                        conn.Dispose();
-                        using (MsSqlConnector conn1 = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, "master"))
-                        {
-                            try
-                            {
-                                conn1.CreateConnection(out ErrorInfo);
-                                conn1.OpenConnection(out ErrorInfo);
-
-                                // create datagbase
-                                Logging.ATSAdminLog.Info(string.Format("Creating Database {0}", ATSGlobals.strDatabaseName));
-                                RunScript(SQLServerResources.CreateDatabase, conn1, out ErrorInfo);
-                                Logging.ATSAdminLog.Info(string.Format("Created Database {0}", ATSGlobals.strDatabaseName));
-
-                                // create tables
-                                Logging.ATSAdminLog.Info(string.Format("Creating Tables in {0} Database", ATSGlobals.strDatabaseName));
-                                RunScript(SQLServerResources.CreateTables, conn1, out ErrorInfo);
-                                Logging.ATSAdminLog.Info(string.Format("Created Tables in {0} Database", ATSGlobals.strDatabaseName));
-                            }
-                            catch (Exception ex1)
-                            {
-                                if (ErrorInfo == null) { ErrorInfo = new Exception(ex1.Message, ex); }
-                            }
-                        }
-                    }
-                    catch (Exception ex1)
-                    {
-                        if (ErrorInfo == null) { ErrorInfo = new Exception(ex1.Message, ex); }
-                    }
-                }
-            }
-            if (ErrorInfo != null) { return false; }
-            #endregion
-            #region Database version check
-            // Now that you are connected to Express, check the database versions
-            Version databaseVersion; // The current version of the database
-            int chkVer = CheckVersion(out databaseVersion);
-            VersionCheck verChk = (VersionCheck)chkVer;
-            //MessageBox.Show(string.Format("Version Check: {0} Version: {1}", verChk.ToString(), databaseVersion.ToString()));
-            Logging.ATSAdminLog.InfoFormat("Database Version Check: {0} .... Database Version: {1}", verChk.ToString(), databaseVersion.ToString());
-            switch (chkVer)
-            {
-                case (int)VersionCheck.Equal:
-                    {
-                        bContinue = true;
-                        break;
-                    }
-                case (int)VersionCheck.Failed:
-                    {
-                        bContinue = false;
-                        break;
-                    }
-                case (int)VersionCheck.DatabaseIsOlder:
-                    {
-                        using (MsSqlConnector conn = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, ATSGlobals.strDatabaseName))
-                        {
-                            try
-                            {
-                                conn.CreateConnection(out ErrorInfo);
-                                conn.OpenConnection(out ErrorInfo);
-                                #region database upggrade scripts
-                                switch (databaseVersion.ToString())
-                                {
-                                    // Run the apropriate upgdrade script(s)
-                                    case "1.0.0.0":
-                                        {   // Current database is version 1.0.0.0, update to 1.0.0.1
-                                            Logging.ATSAdminLog.InfoFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.0", "1.0.0.1");
-                                            bContinue = RunScript(SQLServerResources.UpdateDatabase1, conn, out ErrorInfo);
-                                            Logging.ATSAdminLog.InfoFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.0", "1.0.0.1");
-                                            goto case "1.0.0.1"; // Continue and upgrade one more step
-                                        }
-                                    case "1.0.0.1":
-                                        {   // Current database is version 1.0.0.1, update to 1.0.0.2
-                                            Logging.ATSAdminLog.InfoFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.1", "1.0.0.2");
-                                            bContinue = RunScript(SQLServerResources.UpdateDatabase2, conn, out ErrorInfo);
-                                            Logging.ATSAdminLog.InfoFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.2");
-                                            goto case "1.0.0.2"; // Continue and upgrade one more step
-                                        }
-                                    case "1.0.0.2":
-                                        {   // Current database is version 1.0.0.2, update to 1.0.0.3
-                                            Logging.ATSAdminLog.InfoFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.3");
-                                            bContinue = RunScript(SQLServerResources.UpdateDatabase3, conn, out ErrorInfo);
-                                            Logging.ATSAdminLog.InfoFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.3");
-                                            goto case "1.0.0.3"; // Continue and upgrade one more step
-                                        }
-                                    case "1.0.0.3":
-                                        {   // Current database is version 1.0.0.3, update to 1.0.0.4
-                                            Logging.ATSAdminLog.InfoFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.3", "1.0.0.4");
-                                            bContinue = RunScript(SQLServerResources.UpdateDatabase4, conn, out ErrorInfo);
-                                            Logging.ATSAdminLog.InfoFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.4", "1.0.0.4");
-                                            break;
-                                        }
-                                    default:
-                                        {
-                                            //MessageBox.Show("Error: Not able to upgrade database (51188)");
-                                            if (databaseVersion == new Version(0, 0, 0, 0))
-                                            {
-                                                string format = string.Format("Database version is {0}, this should have been auto upgraded to {1}", databaseVersion.ToString(), ATSGlobals.strDatabaseVersion);
-                                                Logging.ATSAdminLog.Fatal(format);
-                                                MessageBox.Show(format);
-                                            }
-                                            else
-                                            {
-                                                string format = string.Format("Failed to upgrade Database from version: {0} to version: {1}", databaseVersion.ToString(), ATSGlobals.strDatabaseVersion);
-                                                Logging.ATSAdminLog.Fatal(format);
-                                                MessageBox.Show(format);
-                                            }
-                                            break;
-                                        }
-                                }
-#endregion
-                            }
-                            catch (Exception ex)
-                            {
-                                if (ErrorInfo == null) { ErrorInfo = ex; }
-                            }                            
-                        }
-                        break;
-                    }
-                case (int)VersionCheck.DatabaseIsMoreNew:
-                    {
-                        bContinue = false;
-                        break;
-                    }
-                default:
-                    {
-                        bContinue = false;
-                        break; 
-                    }
+            #region comment-code
+            //            #region Database Creation support
+//            using (MsSqlConnector conn = new MsSqlConnector(ProSupport.strDatabaseServer, ProSupport.strDatabaseInstance, ATSGlobals.strDatabaseName))
+//            {
+//                try
+//                {
+//                    conn.CreateConnection(out ErrorInfo);
+//                    conn.OpenConnection(out ErrorInfo);
+//                }
+//                catch (Exception ex) 
+//                {
+//                    try
+//                    {
+//                        conn.Dispose();
+//                        using (MsSqlConnector conn1 = new MsSqlConnector(ProSupport.strDatabaseServer, ProSupport.strDatabaseInstance, "master"))
+//                        {
+//                            try
+//                            {
+//                                conn1.CreateConnection(out ErrorInfo);
+//                                conn1.OpenConnection(out ErrorInfo);
+
+//                                // create datagbase
+//                                Logging.ATSAdminLog.Info(string.Format("Creating Database {0}", ATSGlobals.strDatabaseName));
+//                                RunScript(SQLServerResources.CreateDatabase, conn1, out ErrorInfo);
+//                                Logging.ATSAdminLog.Info(string.Format("Created Database {0}", ATSGlobals.strDatabaseName));
+
+//                                // create tables
+//                                Logging.ATSAdminLog.Info(string.Format("Creating Tables in {0} Database", ATSGlobals.strDatabaseName));
+//                                RunScript(SQLServerResources.CreateTables, conn1, out ErrorInfo);
+//                                Logging.ATSAdminLog.Info(string.Format("Created Tables in {0} Database", ATSGlobals.strDatabaseName));
+//                            }
+//                            catch (Exception ex1)
+//                            {
+//                                if (ErrorInfo == null) { ErrorInfo = new Exception(ex1.Message, ex); }
+//                            }
+//                        }
+//                    }
+//                    catch (Exception ex1)
+//                    {
+//                        if (ErrorInfo == null) { ErrorInfo = new Exception(ex1.Message, ex); }
+//                    }
+//                }
+//            }
+//            if (ErrorInfo != null) { throw ErrorInfo; }
+//            #endregion
+//            #region Database version check
+//            // Now that you are connected to Express, check the database versions
+//            Version databaseVersion; // The current version of the database
+//            int chkVer = CheckVersion(out databaseVersion);
+//            VersionCheck verChk = (VersionCheck)chkVer;
+//            //MessageBox.Show(string.Format("Version Check: {0} Version: {1}", verChk.ToString(), databaseVersion.ToString()));
+//            Logging.ATSAdminLog.InfoFormat("Database Version Check: {0} .... Database Version: {1}", verChk.ToString(), databaseVersion.ToString());
+//            switch (chkVer)
+//            {
+//                case (int)VersionCheck.Equal:
+//                    {
+//                        bContinue = true;
+//                        break;
+//                    }
+//                case (int)VersionCheck.Failed:
+//                    {
+//                        bContinue = false;
+//                        break;
+//                    }
+//                case (int)VersionCheck.DatabaseIsOlder:
+//                    {
+//                        using (MsSqlConnector conn = new MsSqlConnector(ProSupport.strDatabaseServer, ProSupport.strDatabaseInstance, ATSGlobals.strDatabaseName))
+//                        {
+//                            try
+//                            {
+//                                conn.CreateConnection(out ErrorInfo);
+//                                conn.OpenConnection(out ErrorInfo);
+//                                #region database upggrade scripts
+//                                switch (databaseVersion.ToString())
+//                                {
+//                                    // Run the apropriate upgdrade script(s)
+//                                    case "1.0.0.0":
+//                                        {   // Current database is version 1.0.0.0, update to 1.0.0.1
+//                                            Logging.ATSAdminLog.InfoFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.0", "1.0.0.1");
+//                                            bContinue = RunScript(SQLServerResources.UpdateDatabase1, conn, out ErrorInfo);
+//                                            Logging.ATSAdminLog.InfoFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.0", "1.0.0.1");
+//                                            goto case "1.0.0.1"; // Continue and upgrade one more step
+//                                        }
+//                                    case "1.0.0.1":
+//                                        {   // Current database is version 1.0.0.1, update to 1.0.0.2
+//                                            Logging.ATSAdminLog.InfoFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.1", "1.0.0.2");
+//                                            bContinue = RunScript(SQLServerResources.UpdateDatabase2, conn, out ErrorInfo);
+//                                            Logging.ATSAdminLog.InfoFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.2");
+//                                            goto case "1.0.0.2"; // Continue and upgrade one more step
+//                                        }
+//                                    case "1.0.0.2":
+//                                        {   // Current database is version 1.0.0.2, update to 1.0.0.3
+//                                            Logging.ATSAdminLog.InfoFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.3");
+//                                            bContinue = RunScript(SQLServerResources.UpdateDatabase3, conn, out ErrorInfo);
+//                                            Logging.ATSAdminLog.InfoFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.2", "1.0.0.3");
+//                                            goto case "1.0.0.3"; // Continue and upgrade one more step
+//                                        }
+//                                    case "1.0.0.3":
+//                                        {   // Current database is version 1.0.0.3, update to 1.0.0.4
+//                                            Logging.ATSAdminLog.InfoFormat("Upgrading Database from version: {0} to version: {1}", "1.0.0.3", "1.0.0.4");
+//                                            bContinue = RunScript(SQLServerResources.UpdateDatabase4, conn, out ErrorInfo);
+//                                            Logging.ATSAdminLog.InfoFormat("Upgraded Database from version: {0} to version: {1}", "1.0.0.4", "1.0.0.4");
+//                                            break;
+//                                        }
+//                                    default:
+//                                        {
+//                                            //MessageBox.Show("Error: Not able to upgrade database (51188)");
+//                                            if (databaseVersion == new Version(0, 0, 0, 0))
+//                                            {
+//                                                string format = string.Format("Database version is {0}, this should have been auto upgraded to {1}", databaseVersion.ToString(), ATSGlobals.strDatabaseVersion);
+//                                                Logging.ATSAdminLog.Fatal(format);
+//                                                MessageBox.Show(format);
+//                                            }
+//                                            else
+//                                            {
+//                                                string format = string.Format("Failed to upgrade Database from version: {0} to version: {1}", databaseVersion.ToString(), ATSGlobals.strDatabaseVersion);
+//                                                Logging.ATSAdminLog.Fatal(format);
+//                                                MessageBox.Show(format);
+//                                            }
+//                                            break;
+//                                        }
+//                                }
+//#endregion
+//                            }
+//                            catch (Exception ex)
+//                            {
+//                                if (ErrorInfo == null) { ErrorInfo = ex; }
+//                            }                            
+//                        }
+//                        break;
+//                    }
+//                case (int)VersionCheck.DatabaseIsMoreNew:
+//                    {
+//                        bContinue = false;
+//                        break;
+//                    }
+//                default:
+//                    {
+//                        bContinue = false;
+//                        break; 
+//                    }
 
-            }
+//            }
+            //            #endregion
             #endregion
-            sqlCon.Close();
-            sqlCon.Dispose();
-            sqlCmd.Connection.Close();
-            sqlCmd.Connection.Dispose(); 
             return bContinue;
         }
 
@@ -221,7 +218,7 @@
                 int db_count = -1;
                 //Verify that the AnywhereTS database exists
                 #region Get Database Count
-                using (MsSqlConnector conn = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, ATSGlobals.strDatabaseName))
+                using (MsSqlConnector conn = new MsSqlConnector(ProSupport.strDatabaseServer, ProSupport.strDatabaseInstance, ATSGlobals.strDatabaseName))
                 {
                     try
                     {
@@ -263,7 +260,7 @@
                 else if (db_count == 0)
                 {
                     #region Database Creation support
-                    using (MsSqlConnector conn = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, ATSGlobals.strDatabaseName))
+                    using (MsSqlConnector conn = new MsSqlConnector(ProSupport.strDatabaseServer, ProSupport.strDatabaseInstance, ATSGlobals.strDatabaseName))
                     {
                         try
                         {
@@ -275,7 +272,7 @@
                             try
                             {
                                 conn.Dispose();
-                                using (MsSqlConnector conn1 = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, "master"))
+                                using (MsSqlConnector conn1 = new MsSqlConnector(ProSupport.strDatabaseServer, ProSupport.strDatabaseInstance, "master"))
                                 {
                                     try
                                     {
@@ -310,7 +307,7 @@
 
                 
                 #region Get Database Version
-                using (MsSqlConnector conn = new MsSqlConnector(Properties.Settings.Default.DBServer, Properties.Settings.Default.DBInstance, ATSGlobals.strDatabaseName))
+                using (MsSqlConnector conn = new MsSqlConnector(ProSupport.strDatabaseServer, ProSupport.strDatabaseInstance, ATSGlobals.strDatabaseName))
                 {
                     try
                     {
@@ -401,7 +398,7 @@
                 #endregion
                 
           
-                sqlCon.Close();
+                //sqlCon.Close();
 
                 if (vDb == v)
                     return (int)VersionCheck.Equal;

 

  ViewVC Help
Powered by ViewVC 1.1.22