/[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/12 12:41:04	41
+++ trunk/TSAdminTool/Database.cs	2012/07/12 12:59:45	44
@@ -27,7 +27,6 @@
         private SqlCommand sqlCmd = new SqlCommand();
 
         const string SQL_BROWSER_SERVICE_NAME = "SQLBrowser";
-        static Version CURRENT_DB_VERSION = new Version(1, 0, 0, 3);
         public static string InstanceName
         {
             get
@@ -58,7 +57,7 @@
                 {
                     Logging.ATSAdminLog.Debug("Opening connection to AnywhereTS Database");
                 }
-                sqlCon.Open();
+                if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
             }
             catch
             {
@@ -71,7 +70,7 @@
                     {
                         Logging.ATSAdminLog.Debug("Creating Database AnywhereTS");
                         sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
-                        sqlCon.Open();
+                        if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
                         RunScript(Resource1.CreateDatabase.ToString());
                         sqlCon.Close();
                     }
@@ -81,9 +80,9 @@
                     {
                         Logging.ATSAdminLog.Debug("Creating Tables in AnywhereTS Database");
                         sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
-                        sqlCon.Open();
+                        if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
                         RunScript(Resource1.CreateTables.ToString());
-                        sqlCon.Close();
+                        //sqlCon.Close();
                     }
                     Logging.ATSAdminLog.Debug("Created Tables in AnywhereTS Database");
                 }
@@ -149,13 +148,13 @@
                                     //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(), CURRENT_DB_VERSION.ToString());
+                                        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(), CURRENT_DB_VERSION.ToString());
+                                        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);
                                     }                                    
@@ -230,8 +229,9 @@
                 using (log4net.NDC.Push(string.Format("SQL STATMENT={0}", "select count(*) from master..sysdatabases where name='AnywhereTS'")))
                 {
                     Logging.ATSAdminLog.Debug("Getting Coount of AnywhereTS databases");
-                      sqlCmd = new SqlCommand("select count(*) from master..sysdatabases where name='AnywhereTS'", sqlCon);
-                        strResult = sqlCmd.ExecuteScalar().ToString();
+                    if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
+                    sqlCmd = new SqlCommand("select count(*) from master..sysdatabases where name='AnywhereTS'", sqlCon);
+                    strResult = sqlCmd.ExecuteScalar().ToString();
                 }
                Logging.ATSAdminLog.DebugFormat("AnywhereTS databases Count={0}", strResult);
 
@@ -243,7 +243,7 @@
                     {
                         Logging.ATSAdminLog.Debug("Creating Database AnywhereTS in CheckVersion()");
                         sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
-                        sqlCon.Open();
+                        if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
                         RunScript(Resource1.CreateDatabase.ToString());
                         sqlCon.Close();
                     }
@@ -253,7 +253,7 @@
                     {
                         Logging.ATSAdminLog.Debug("Creating Tables in AnywhereTS Database in CheckVersion()");
                         sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
-                        sqlCon.Open();
+                        if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
                         RunScript(Resource1.CreateTables.ToString());
                         sqlCon.Close();
                     }
@@ -266,7 +266,7 @@
                         Logging.ATSAdminLog.Debug("Gettting AnywhereTS Database Version");
                         sqlCon.Close();
                         sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString);
-                        sqlCon.Open();
+                        if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
                         sqlCmd = new SqlCommand("SELECT value from AnywhereTS..AppInfo where property='version'", sqlCon);
                         strResult = (string)sqlCmd.ExecuteScalar();
                         sqlCon.Close();
@@ -287,7 +287,7 @@
                         {
                             Logging.ATSAdminLog.Debug("Creating Tables in AnywhereTS Database in CheckVersion()");
                             sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
-                            sqlCon.Open();
+                            if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
                             RunScript(Resource1.CreateTables.ToString());
                             sqlCon.Close();
                         }
@@ -298,7 +298,7 @@
                             Logging.ATSAdminLog.Debug("Gettting AnywhereTS Database Version");
                             sqlCon.Close();
                             sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString);
-                            sqlCon.Open();
+                            if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
                             sqlCmd = new SqlCommand("SELECT value from AnywhereTS..AppInfo where property='version'", sqlCon);
                             strResult = (string)sqlCmd.ExecuteScalar();
                             sqlCon.Close();

 

  ViewVC Help
Powered by ViewVC 1.1.22