/[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/11 19:34:51	21
+++ trunk/TSAdminTool/Database.cs	2012/07/11 20:13:17	22
@@ -72,6 +72,10 @@
                     sqlCon.Open();
                     RunScript(Resource1.CreateDatabase.ToString());
                     sqlCon.Close();
+                    sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
+                    sqlCon.Open();
+                    RunScript(Resource1.CreateTables.ToString());
+                    sqlCon.Close();
                     sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString);
                     sqlCon.Open();
                 }
@@ -197,53 +201,42 @@
 
                 if (strResult == "0")
                 {
-
                     sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
                     sqlCon.Open();
                     RunScript(Resource1.CreateDatabase.ToString());
                     sqlCon.Close();
-                }
-                else
-                {
-                    sqlCon.Close();
                     sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
                     sqlCon.Open();
-                    RunScript("DROP DATABASE AnywhereTS");
-                    sqlCon.Close();
-                    sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
-                    sqlCon.Open();
-                    RunScript(Resource1.CreateDatabase.ToString());
+                    RunScript(Resource1.CreateTables.ToString());
                     sqlCon.Close();
                 }
-
                 try
                 {
                     sqlCon.Close();
                     sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString);
+                    sqlCon.Open();
                     sqlCmd = new SqlCommand("SELECT value from AnywhereTS..AppInfo where property='version'", sqlCon);
                     strResult = (string)sqlCmd.ExecuteScalar();
+                    sqlCon.Close();
                 }
                 catch
                 {
-                    // database exists, but does not have one or more expected tables
+                    // the database exists, but one or more tables are missing
                     try
                     {
-                        sqlCon.Close();
                         sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
                         sqlCon.Open();
-                        RunScript("DROP DATABASE AnywhereTS");
+                        RunScript(Resource1.CreateTables.ToString());
                         sqlCon.Close();
-                        sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
-                        sqlCmd.Connection = sqlCon;
-                        sqlCmd.CommandText = Resource1.CreateDatabase.ToString();
-                        sqlCmd.ExecuteNonQuery();
-                        sqlCon.Close();
-
                         sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString);
+                        sqlCon.Open();
                         sqlCmd = new SqlCommand("SELECT value from AnywhereTS..AppInfo where property='version'", sqlCon);
                         strResult = (string)sqlCmd.ExecuteScalar();
                     }
-                    catch { return (int)VersionCheck.Failed; }
+                    catch
+                    {
+                        return (int)VersionCheck.Failed;
+                    }
                 }
                 vDb = new Version(strResult);
           

 

  ViewVC Help
Powered by ViewVC 1.1.22