Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run External EXE from Sql Server

Status
Not open for further replies.

ehenry

Programmer
Sep 18, 2009
65
US
Is there a way to trigger a program to start running from SQL Server?

What I have is a database that is scheduled to update on a daily basis. After this update I want to open an excel file. The excel file will pull the data it needs automatically to produce a report. I can have the file open using an external program, I was just curious if there was a way to do it from within SQL server.

Thank you for any help on this.
 
Thank you,

I am looking into xp_cmdshell but can't seem to make it open an excel file. There is no run or open command. I have
EXEC xp_cmdshell 'copy c:\test.xlsx',NO_OUTPUT but no luck.

What alternative would you suggest rather than using xp_cmdshell?
 
Would it be possible to do this using the SQL Server Agent?
 
try using a linked server and schedule a job to copy that data from SQL Server to the excel file.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Your problem is that you said you want to "open an excel file," but based on your code, it looks like you're trying to copy a file. If you want to open Excel and have it load a specific file, try calling the Excel executable and then passing in an argument for the file you wish to open. Here is reference for command line arguments in Excel:

But I think you're going to have a larger problem. SQL Server runs under a service account. So you'll never see a file open because the Excel process will execute under the service account. Who knows if your Excel VBA routines will even work without the user interface??

I would take a step back and think about re-engineering your solution.

Is the Excel file used simply as a report? If it is, then think about using something like SSIS to export data from SQL Server out to an Excel file.
 
Thanks for the input. The Excel file must be used, it is actually a complex calculator run by VBA, I don't see any other way around using it. I am looking into using the sql Server Agent CmdExec right now.
 
Not trying to be offensive, but that's a very unstable foundation for an information system. I'd never let anything like that out into production in my sphere of influence.
 
I think you would see it differently with an idea of what the entire process is. Thanks for you input though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top