/[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 10 by william, Wed Jul 11 16:01:40 2012 UTC revision 17 by william, Wed Jul 11 16:48:23 2012 UTC
# Line 21  namespace AnywhereTS Line 21  namespace AnywhereTS
21          private SqlCommand sqlCmd = new SqlCommand();          private SqlCommand sqlCmd = new SqlCommand();
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(@";", "");
26          public bool SetupDatabase()          public bool SetupDatabase()
27          {          {
28              bool bContinue = false;              bool bContinue = false;
# Line 34  namespace AnywhereTS Line 35  namespace AnywhereTS
35              }              }
36              catch (SqlException sql_ex)              catch (SqlException sql_ex)
37              {              {
38                  MessageBox.Show("Fail to connect to SQL Server Express\n" + 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              }              }
41                    
# Line 265  namespace AnywhereTS Line 266  namespace AnywhereTS
266              }              }
267              catch              catch
268              {              {
269                  MessageBox.Show("Error, could not configure SQL Browser service (24888). Please check that SQL Server Express is intalled and that you are logged in with sufficient rights to configure services. Then retry the operation.");                  MessageBox.Show("Error, could not configure SQL Browser service (24888). Please check that SQL Server is intalled and that you are logged in with sufficient rights to configure services. Then retry the operation.");
270              }              }
271          }          }
272    
# Line 284  namespace AnywhereTS Line 285  namespace AnywhereTS
285              {              {
286                  prot.Get();                  prot.Get();
287                  if ((string)prot.GetPropertyValue("ProtocolName") == "Np" &&  //Named pipes                  if ((string)prot.GetPropertyValue("ProtocolName") == "Np" &&  //Named pipes
288                      (string)prot.GetPropertyValue("InstanceName") == "SQLEXPRESS")                      (string)prot.GetPropertyValue("InstanceName") == InstanceName)
289                  {   // We found the named pipes protocol                  {   // We found the named pipes protocol
290                      if (!(bool)prot.GetPropertyValue("Enabled"))                      if (!(bool)prot.GetPropertyValue("Enabled"))
291                      {   // Named pipes not activated                      {   // Named pipes not activated
# Line 292  namespace AnywhereTS Line 293  namespace AnywhereTS
293                                
294                          // Check if user wants to restart SQL server                          // Check if user wants to restart SQL server
295                          DialogResult resultRights;                          DialogResult resultRights;
296                          resultRights = MessageBox.Show("In order for users to use the AnywhereTS control panel, the SQL Express service on this computer need to be restarted. This operation might take up to 60 seconds. Do you want restart the SQL Express service now?", "AnywhereTS - Restart SQL Express (This operation might take up to 60 seconds!)", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);                          resultRights = MessageBox.Show(string.Format("In order for users to use the AnywhereTS control panel, the {0} service on this computer need to be restarted. This operation might take up to 60 seconds. Do you want restart the {0} service now?", InstanceName), string.Format("AnywhereTS - Restart {0} (This operation might take up to 60 seconds!)", InstanceName), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
297                          if (resultRights == DialogResult.Yes)                          if (resultRights == DialogResult.Yes)
298                          {                          {
299                              // Restart the SQL server                              // Restart the SQL server
# Line 301  namespace AnywhereTS Line 302  namespace AnywhereTS
302                              foreach (ManagementObject svc in sqlServicesMan.GetInstances())                              foreach (ManagementObject svc in sqlServicesMan.GetInstances())
303                              {                              {
304                                  if ((uint)svc.GetPropertyValue("SqlServiceType") == sqlServerService &&                                  if ((uint)svc.GetPropertyValue("SqlServiceType") == sqlServerService &&
305                                      (string)svc.GetPropertyValue("ServiceName") == "MSSQL$SQLEXPRESS")                                      (string)svc.GetPropertyValue("ServiceName") == string.Format("MSSQL${0}", InstanceName))
306                                  {                                  {
307                                      svc.Get();                                      svc.Get();
308                                      if ((uint)svc.GetPropertyValue("State") != sqlServiceStopped)                                      if ((uint)svc.GetPropertyValue("State") != sqlServiceStopped)

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

  ViewVC Help
Powered by ViewVC 1.1.22