0

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 .

Ofir
  • 5,049
  • 5
  • 36
  • 61
  • wait for console input in some cases? (eg. psexec asking for remote password). Clearly this kind of endeavour is better fitted for a process *outside* sqlservr.exe – Remus Rusanu Aug 20 '13 at 07:55
  • what you mean in "psexec asking for remote password?" my psexec is running under the Sql Server user. my console applications runs without an input (except the command line parameters) – Ofir Aug 20 '13 at 08:00
  • psexec is not running under SQL Server service account if you connect with Windows login. It will run under impersonated account and thus cause Kerberos "double hop", requiring constrained delegation to be set up. – Remus Rusanu Aug 20 '13 at 10:16

1 Answers1

0

Try the following proxy configuration of your console app in app.config:

<system.net>
   <defaultProxy
      enabled="false"
      useDefaultCredentials="false"
    />
</system.net>
chridam
  • 100,957
  • 23
  • 236
  • 235