/[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

revision 17 by william, Wed Jul 11 16:48:23 2012 UTC revision 18 by william, Wed Jul 11 17:45:48 2012 UTC
# Line 22  namespace AnywhereTS Line 22  namespace AnywhereTS
22    
23          const string SQL_BROWSER_SERVICE_NAME = "SQLBrowser";          const string SQL_BROWSER_SERVICE_NAME = "SQLBrowser";
24    
25          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", "");
26          public bool SetupDatabase()          public bool SetupDatabase()
27          {          {
28              bool bContinue = false;              bool bContinue = false;
29                bool bCreateDB = false;
30              // Create a connection to SQL Server              // Create a connection to SQL Server
31              try              try
32              {              {
# Line 35  namespace AnywhereTS Line 35  namespace AnywhereTS
35              }              }
36              catch (SqlException sql_ex)              catch (SqlException sql_ex)
37              {              {
38                  MessageBox.Show(string.Format("Fail to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString());                  //MessageBox.Show(string.Format("Fail to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex.Number.ToString() + " " + sql_ex.Message.ToString());
39                  return bContinue;                  //return bContinue;
40                    //bCreateDB = true;
41                    try
42                    {
43                        sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString.Replace("AnywhereTS","master");
44                        sqlCon.Open();
45                        RunScript(Resource1.CreateDatabase.ToString());
46                        sqlCon.Close();
47                        sqlCon.ConnectionString = Properties.Settings.Default.atsConnectionString;
48                        sqlCon.Open();
49                    }
50                    catch (SqlException sql_ex1)
51                    {
52                        MessageBox.Show(string.Format("Fail to connect to SQL Server Instance: {0}\n", InstanceName) + sql_ex1.Number.ToString() + " " + sql_ex1.Message.ToString());
53                        return bContinue;
54                    }
55              }              }
56                    
57              // Now that you are connected to Express, check the database versions              // Now that you are connected to Express, check the database versions
58    
59              Version databaseVersion; // The current version of the database              Version databaseVersion; // The current version of the database
60    
61              switch (CheckVersion(out databaseVersion))              int chkVer = CheckVersion(out databaseVersion);
62                VersionCheck verChk = (VersionCheck)chkVer;
63                //MessageBox.Show(string.Format("Version Check: {0} Version: {1}", verChk.ToString(), databaseVersion.ToString()));
64    
65                switch (chkVer)
66              {              {
67                  case (int)VersionCheck.Equal:                  case (int)VersionCheck.Equal:
68                      {                      {
# Line 178  namespace AnywhereTS Line 197  namespace AnywhereTS
197                      //Drop the database                      //Drop the database
198                      sqlCmd = new SqlCommand("IF EXISTS(SELECT * FROM sysdatabases WHERE name='AnywhereTS')DROP DATABASE AnywhereTS", sqlCon);                      sqlCmd = new SqlCommand("IF EXISTS(SELECT * FROM sysdatabases WHERE name='AnywhereTS')DROP DATABASE AnywhereTS", sqlCon);
199                      strResult = (string)sqlCmd.ExecuteScalar();                      strResult = (string)sqlCmd.ExecuteScalar();
200                      return (int)VersionCheck.DatabaseNotFound;                                              return (int)VersionCheck.DatabaseNotFound;
201                  }                  }
202                  vDb = new Version(strResult);                  vDb = new Version(strResult);
203                        

Legend:
Removed from v.17  
changed lines
  Added in v.18

  ViewVC Help
Powered by ViewVC 1.1.22