/[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/12 10:52:05	33
@@ -6,11 +6,13 @@
 using System.Windows.Forms;
 using System.Text.RegularExpressions;
 using System.Management;
+using log4net;
 
 namespace AnywhereTS
 {
     class DatabaseSupport
     {
+        private readonly ILog logger = LogManager.GetLogger("AnywhereTS.ATSAmdinLogger"); 
         enum VersionCheck
         {
             Failed = 0, 
@@ -47,6 +49,7 @@
         {
             bool bContinue = false;
             // Create a connection to SQL Server
+            logger.Debug("SetupDatabase() called ");
             try
             {
                 sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString;
@@ -59,21 +62,16 @@
                 //bCreateDB = true;
                 try
                 {
-                    try
-                    {
-                        sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString);
-                        sqlCon.Open();
-                        RunScript("DROP AnywhereTS");
-                        sqlCon.Close();
-                    }
-                    catch { }
-
                     sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master"));
                     sqlCon.Open();
                     RunScript(Resource1.CreateDatabase.ToString());
                     sqlCon.Close();
-                    sqlCon = new SqlConnection(Properties.Settings.Default.atsConnectionString);
+                    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();
                 }
                 catch (SqlException sql_ex1)
                 {
@@ -197,53 +195,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