Hey guys.
I am wondering if it is possible to execute an .exe from a stored proc. I have an application that calls a stored proc and I am wanting for that stored proc to call up an app to show certain results. I have no way of doing this on the application itself as I dont have the source code. So, since I do have access to the SQL I am wondering if it could be done there.
Thanks
tiboryou can launch an exe from a proc with xp_cmdshell. you can't display any of it's output though, except for whatever it writes to stdout.
if it's a GUI app, there's no point to it. Also, remember that this app would have to be located on the server.
Be very careful with this. If you enable xp_cmdshell, it opens up a fairly large security hole on your db server. Make sure only appropriate logins have perms to execute it. don't give any clients permissions to execute it directly or you may find that a criminal has stolen all your data.|||It's not advisable
You could bring down the server from what I understand
But if you want to try you need to use master..xp_cmdshell
But if you don't know about the sproc, then I'd really advise against it|||Thanks guys
Turns out, I may be able to avoid the project in its entirety but this is good info to know for the future.
Again, very much appreciated :)|||just be careful if you ever decide to use it. xp_cmdshell is a cross between a loaded gun and a vial of nitroglycerin.|||just be careful if you ever decide to use it. xp_cmdshell is a cross between a loaded gun and a vial of nitroglycerin.
pffffftttttt
The real danger is trying to launch an application with it
Hey DROP Database is kinda dangerous as well|||the real danger is that you can use xp_cmdshell to do anything you could do from a command prompt, which is pretty much anything.
if the wrong people have rights to execute xp_cmdshell, you are in trouble. so best left disabled.|||if the wrong people have rights to execute xp_cmdshell, you are in trouble.
Of course, would you give a gun to a toddler?
so best left disabled.
Couldn't disagree more|||Tibor, don't listen to Brett.
he's a wild vocalist (http://www.rockdetector.com/artist,5489.sm) for an all-girl 80's hair-metal band. everyone knows such types can't be trusted.
:)|||belly aching laughter. on the floor. verge of tears.
but really if your shop is not locked down with regards to db server security, shame on you. Although I have been somewhere that refused to be locked down. So I left.
I find xp_cmdshell extremely useful especially combined with osql. I do my database builds that way by doing a fresh dump from source control and letting those rip with a little cursor and some logging. A little Redgate afterwards to be sure and everything is right as rain.|||Hi,
I've quite the same Problem as Tibor.
I also try to call a .exe from a trigger.
The .exe is a VB.Net command line application, that shall invoke a ETL script on a third party BI Application. The VB application first calls the getObject Function and then calls the Reload Function of the BI application.
This application works fine, when I start it in the command line.
But when I try to call it with the xp_cmdshell proc the execution stucks and after a while an exception is thrown ("ActiveX component couldn't be started" or so on)
Until now, I haven't found any way to fix this problem.
Now I'm searching for another way of calling an .exe from a trigger. I don't know, if this helps. Maybe you have any suggestions to deal with this problem
Thanks in advance
Gojo|||you want to call an exe from a trigger? pardon me, but that's a less than good idea. It's quite bad actually.
triggers need to have a very constrained scope - they shouldn't be launching other processes, sending emails, writing data to remote servers, calculating your horoscope, or anything like that.
if you do somehow figure out how to launch an exe from a trigger, the perf or your application will suffer big time.
what are you trying to achieve with this? why do you think launching an exe is the way to do it?|||triggers need to have a very constrained scope - they shouldn't be launching other processes, sending emails, writing data to remote servers, calculating your horoscope, or anything like that.
If you're using SQL Server 2005, you can use the Service Broker to do such "crazy" stuff without ending up with long running transactions.|||Thanks for the fast replies
@. jezemine
I know, the idea sonds weird. My problem is, that I want to keep my data in the dashboard event triggered.
In this case a new DB entry is a event. But when I'm constantly polling the table (as I do now) the solution isn't event triggered. The only way to achieve this, is to call the .exe (which calls the load script), when there is a new entry in the table (therefore the trigger).
Do you have another idea how to accomplish that (I mean how to tell my .exe that there's a new entry, so that the .exe can call the load script)?
@.kaffenils
Unfortunately I have to use the 2000 version
thanks
gojo|||you could write an app that polls the table every so often, and when there's a new row then it executes your load script.
I don't understand what you mean by "the solution isn't even triggered" btw.|||Currently I poll the table every 5 secs. If there's a new row, I execute my script. This works fine, but as I wrote before, this solution is not what I actually want.
I don't want a permanent polling. I want the new Table entry to be the "initiator" of the script execution. When I poll the table, the poll query is the "initiator".
I hope I could make clear, what I want.
thanks
gojo|||Maybe my Problem could be solved another way.
Is there a possibility in SQL Server 2000 to access a class which is written in .NET and which is "stored" in the Global Assembly Cache (GAC)?
Then I could access the reload command.
Thanks gojo|||I'd probably create a SQL Agent job that did whatever "heavy lifting" was required (running the ETL process, etc), then use either sp_start_job (http://msdn2.microsoft.com/En-US/library/aa260289(SQL.80).aspx) or some closely related form of trickery to actually start the job itself.
-PatP|||note that would fail if the job is already running. you can't have two instances of the same job running at once.|||Thanks for the replies.
I've found an interesting site.
http://sqljunkies.com/Article/C5A500EB-B8BE-42C0-B23B-258A342CAAAB.scuk
I think that's exactly what I want.
I hope it works.
thanks gojo|||invoking that kind of thing from a trigger still counts as a no-no in my book.|||I agree, that this shouldn't be implemented in practice.
In my case this solution is more a feasibility study, if that kind of idea (new entry as trigger of a new Data Load) can be implemented in a technical way.|||note that would fail if the job is already running. you can't have two instances of the same job running at once.Failure to start the second instance would be a bad thing? I can't imagine a case where you'd want two separate ETL loads running at once. I suppose that you could queue the subsequent jobs somehow if there was any chance that you really wanted that to happen.
-PatP|||I have no idea if that would be a bad thing or not - depends on OP's requirements. I just stated is as a fyi for the OP.|||Ok so I have been playing around some with xp_cmdshell(yes, I know...not good, lol) but when I run the .exe, my query analyzer hangs up for about 10 minutes.
exec master..xp_cmdshell 'C:\test.exe'
It is just a little vb app i created to test with but it hangs up and does not execute.
I know that I have permissions and such as i can do a simple dos directory seach with it.
Any ideas as to why it hangs up?
Thanks|||It seems to be running it in the processes list of task manager but not actually running the application. Is it possible to actually run the app?|||If your application is expecting someone to click an OK button, you will be waiting a long time.|||Yeah, I just found out that it wont allow it...so i withdraw my question. heh|||If your application is expecting someone to click an OK button, you will be waiting a long time.. ;)|||If your application is expecting someone to click an OK button, you will be waiting a long time.
really? whenever I write a trigger, i have it pop a message box to ask the user if they really want to commit the data. it works great!
:)|||In order to pass a moderate SOX audit, you would have to ask that question twice. "Are you sure you want to commit that data?" "Really sure?"
No comments:
Post a Comment