1

This is my code:

SET @GETCommand = 'curl --silent -X GET -u user:password -H "Content-Type: application/json" "https://jira.com/rest/api/latest/.... > "C:\Test.txt"' 

EXEC xp_cmdshell @GETCommand

When running it outside of Stored Procedure (SP), it takes 2 seconds, however when running it in SP it can take up to 2-3 minutes, why is that?

Please note that I must use variable (@GETCommand) since I've dynamic variables in the SET @GETCommand

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
  • Did you try running cmdshell on the same account that SQL Server uses outside SP? Second try writing file to different location instead of drive C. There is popup window when you try to directly save anything on C drive. It may be default timeout. – Lukasz Szozda Dec 26 '18 at 13:28
  • I grant SQL account user Write access to all C:\ and storing the file in different drive, however I'm still facing the same issue. – user2007221 Dec 26 '18 at 14:53
  • Additional notes is that when I run the command through SQL but not in stored procedure then it takes 2 sec. The problem exist only in the SP. – user2007221 Dec 26 '18 at 14:56
  • 1
    Please post **entire stored procedure**. Probably something else took that time, like building stirng to execute not actual xp_cmdshell call – Lukasz Szozda Dec 26 '18 at 16:51

1 Answers1

0

Using xp_cmdshell is not safe and it could be a security issue. When you want to access to resources out of SQL Server for example, xp_cmdshell, SQL Server does not have any control over any issues occurred. So I strongly suggest you change the solution and create another service or app to do your task, instead, it is the only solution to do your task.

mohabbati
  • 1,162
  • 1
  • 13
  • 31