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; |
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 |
|
|
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 |
|
|
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 |
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 |
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) |