/[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:43:29	43
+++ trunk/TSAdminTool/Database.cs	2012/07/12 13:01:44	45
@@ -57,7 +57,7 @@
                 {
                     Logging.ATSAdminLog.Debug("Opening connection to AnywhereTS Database");
                 }
-                sqlCon.Open();
+                if (sqlCon.State != ConnectionState.Open) sqlCon.Open();
             }
             catch
             {
@@ -70,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();
                     }
@@ -80,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");
                 }
@@ -229,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);
 
@@ -242,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();
                     }
@@ -252,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();
                     }
@@ -263,9 +264,8 @@
                     using (log4net.NDC.Push(string.Format("SQL Statment={0}", "SELECT value from AnywhereTS..AppInfo where property='version'")))
                     {
                         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();
@@ -286,7 +286,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();
                         }
@@ -295,9 +295,8 @@
                         using (log4net.NDC.Push(string.Format("SQL Statment={0}", "SELECT value from AnywhereTS..AppInfo where property='version'")))
                         {
                             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