I wrote some console application and I want execute it through Sql Server using xp_cmdshell
.
So I wrote the following query:
declare @sqlcmd varchar(200)
SET @SQLCmd = 'C:\Automation\ProfileCreator\ProfileManagement.exe ' + @someParameter
EXEC xp_cmdshell @SQLCmd
The console application do some file manipulation and than call PSEXEC to copy another assembly to external server and execute it there.
When I try to run it through cmd it works perfectly (close immediately). When I'm running it through my stored procedure it never stops. Sometimes it execute all the assemblies logic and sometime not. I can`t understand it, What can be the difference between the running methods? (cmd vs xp_cmdshell)
Do you have any I idea how can I solve it out?
BTW - my both assembles finished running with Enviorment.Exit(0 or 1)
. The structure of both of them is like this one:
static void Main(string[] args)
{
try
{
logic..
}
catch (Exception ex)
{
Logger.Log(ex);
Environment.Exit(1);
}
finally
{
Environment.Exit(0);
}
}
So i'm pretty sure that both of my assemblies are return to Sql Server exit value in any case .