Skip to content

Commit

Permalink
Fix unhandled exception to non-existent instance of MSSQL-EXPRESS ins…
Browse files Browse the repository at this point in the history
…talled.
  • Loading branch information
gpgpublickey committed Jan 2, 2018
1 parent a3aabbd commit 10c9aeb
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions FOCA/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,34 @@ public static void WriteErrorInLog(string strMessage)
{
}
}

/// <summary>
/// Validate Service Sql.
/// </summary>
/// <returns></returns>
public static bool IsSQLServerRunning()
{
var process = Process.GetProcessesByName("sqlservr");
if (process.Length == 0) return false;
try
{
var process = Process.GetProcessesByName("sqlservr");
if (process.Length == 0) return false;

//Validate Sql Express
var serviceController = new ServiceController("MSSQL$SQLEXPRESS", Environment.MachineName);
//Validate Sql Express
var serviceController = new ServiceController("MSSQL$SQLEXPRESS", Environment.MachineName);

if (serviceController.DisplayName != null)
return serviceController.Status != ServiceControllerStatus.Stopped;
//Validate Sql Server
serviceController = new ServiceController("MSSQLServer", Environment.MachineName);
if (serviceController.DisplayName != null)
return serviceController.Status != ServiceControllerStatus.Stopped;

//Validate Sql Server
serviceController = new ServiceController("MSSQLServer", Environment.MachineName);

return serviceController.Status != ServiceControllerStatus.Stopped;
return serviceController.Status != ServiceControllerStatus.Stopped;
}
catch (InvalidOperationException e)
{
//Throwed if you are not running an MSSQL EXPRESS instance on the local machine
return false;
}
}

/// <summary>
Expand All @@ -87,9 +95,9 @@ static void Main()

var fsf = new FormSplashFOCA("Open Source");
var t = new Thread(new ThreadStart(delegate
{
Application.Run(fsf);
}));
{
Application.Run(fsf);
}));
t.Start();

//Load the FOCA
Expand Down Expand Up @@ -124,10 +132,10 @@ static void Main()
try
{
fsf.Invoke(new MethodInvoker(delegate
{
fsf.Close();
canStart = true;
}));
{
fsf.Close();
canStart = true;
}));
}
catch
{
Expand Down

0 comments on commit 10c9aeb

Please sign in to comment.