/[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 17:45:48	18
+++ trunk/TSAdminTool/Database.cs	2012/07/11 18:07:00	19
@@ -22,46 +22,59 @@
 
         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(@";Database")).Replace(@"\", "").Replace(@";", "").Replace(@"Database", "");
+        public static string InstanceName
+        {
+            get
+            {
+                bool start = false;
+                bool end = false;
+                List<char> pChars = new List<char>();
+                foreach (char c in Properties.Settings.Default.atsConnectionString.ToCharArray())
+                {
+                    if (c == '\\') { start = true; continue; }
+                    if (c == ';') { end = true; }
+                    if (end) break;
+                    if (start) { pChars.Add(c); }
+                }
+                return new string(pChars.ToArray());
+            }
+        }
         public bool SetupDatabase()
         {
             bool bContinue = false;
-            bool bCreateDB = false;
             // Create a connection to SQL Server
             try
             {
                 sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString;
                 sqlCon.Open();
             }
-            catch (SqlException sql_ex)
+            catch
             {
                 //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.ConnectionString = Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS", "master");
                     sqlCon.Open();
                     RunScript(Resource1.CreateDatabase.ToString());
                     sqlCon.Close();
-                    sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString;
+                    sqlCon = new SqlConnection(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());
+                    SqlException sql_ex = (sql_ex1.GetBaseException() as SqlException);
+                    MessageBox.Show(string.Format("Failed to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString());
                     return bContinue;
                 }
             }
          
             // Now that you are connected to Express, check the database versions
-
             Version databaseVersion; // The current version of the database
-
             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:

 

  ViewVC Help
Powered by ViewVC 1.1.22