/[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 16:48:23	17
+++ trunk/TSAdminTool/Database.cs	2012/07/11 17:45:48	18
@@ -22,11 +22,11 @@
 
         const string SQL_BROWSER_SERVICE_NAME = "SQLBrowser";
 
-        public static string InstanceName = Properties.Settings.Default.atsConnectionString.Substring(Properties.Settings.Default.atsConnectionString.IndexOf(@"\"), Properties.Settings.Default.atsConnectionString.IndexOf(@";")).Replace(@"\", "").Replace(@";", "");
+        public static string InstanceName = Properties.Settings.Default.atsConnectionString.Substring(Properties.Settings.Default.atsConnectionString.IndexOf(@"\"), Properties.Settings.Default.atsConnectionString.IndexOf(@";Database")).Replace(@"\", "").Replace(@";", "").Replace(@"Database", "");
         public bool SetupDatabase()
         {
             bool bContinue = false;
-
+            bool bCreateDB = false;
             // Create a connection to SQL Server
             try
             {
@@ -35,15 +35,34 @@
             }
             catch (SqlException sql_ex)
             {
-                MessageBox.Show(string.Format("Fail to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString());
-                return bContinue;
+                //MessageBox.Show(string.Format("Fail to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString());
+                //return bContinue;
+                //bCreateDB = true;
+                try
+                {
+                    sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS","master");
+                    sqlCon.Open();
+                    RunScript(Resource1.CreateDatabase.ToString());
+                    sqlCon.Close();
+                    sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString;
+                    sqlCon.Open();
+                }
+                catch (SqlException sql_ex1)
+                {
+                    MessageBox.Show(string.Format("Fail to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex1.Number.ToString() + " " + sql_ex1.Message.ToString());
+                    return bContinue;
+                }
             }
          
             // Now that you are connected to Express, check the database versions
 
             Version databaseVersion; // The current version of the database
 
-            switch (CheckVersion(out databaseVersion))
+            int chkVer = CheckVersion(out databaseVersion);
+            VersionCheck verChk = (VersionCheck)chkVer;
+            //MessageBox.Show(string.Format("Version Check: {0} Version: {1}", verChk.ToString(), databaseVersion.ToString()));
+
+            switch (chkVer)
             {
                 case (int)VersionCheck.Equal:
                     {
@@ -178,7 +197,7 @@
                     //Drop the database
                     sqlCmd = new SqlCommand("IF EXISTS(SELECT * FROM sysdatabases WHERE name='AnywhereTS')DROP DATABASE AnywhereTS", sqlCon);
                     strResult = (string)sqlCmd.ExecuteScalar();
-                    return (int)VersionCheck.DatabaseNotFound;                        
+                    return (int)VersionCheck.DatabaseNotFound;
                 }
                 vDb = new Version(strResult);
           

 

  ViewVC Help
Powered by ViewVC 1.1.22