Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...just the few hours I've spent on this site I have learned a lot. I can now implement features that will be very useful to my company, and some of those I never knew existed..."

Geography

Where in the world do Tek-Tips members come from?

Launching a server-side executable through a stored procedure

encore20 (Programmer)
7 Aug 12 15:30
Hi,

I'm new to FoxPro and I was wondering is it possible to launch an executable that is located on a server from a FoxPro stored procedure. The exe is located on the server, but I want to execute from within a FoxPro program. Once executed, the program should run on the server and not the client. Is this possible? I have tried placing a Do prog command on a stored procedure, but it runs on the client side and not the server side. Below is the stored procedure I am attempting to use. I first switch to the server directory and then I call a Do statement.

Procedure executeprog

cd('server path')
Do prog

end proc


Like I said, I am new to FoxPro so this may be way off, any help would be greatly appreciated!
MikeLewis (Programmer)
7 Aug 12 16:05
Hi Encore, and welcome to the forum.

To answer your question, it's necessary to know what kind of server you are talking about. The fact that you mentioned a stored procedure suggests that it is a database server (like SQL Server or Oracle)? Is that right?

Or do you simply mean a file server? Or perhaps a web server?

What you are trying to achieve should certainly be possible, but let's clarify this point before sending you down the wrong road.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

encore20 (Programmer)
7 Aug 12 16:38
Hi Mike,

Thanks for the reply!

You are correct, I am using a database server(SQL Server 2008). I found an example of running a stored procedure using SQLEXEC but it would not run an executable server-side so I was trying to find a way, if possible, to use only FoxPro commands to get the job done.
OlafDoschke (Programmer)
8 Aug 12 2:26
If you want to start an exe from a stored procedure in an SQL Server, that's not a foxpro question, it would rather be a question for an SQL Server forum. I'm using SQL Server, too, but mainly for SQL, not for such unusual approaches. What should the exe do on the server?

One general idea, if you want to run something server side, is to start a service, like SQL Server does, and be able to make requests to that service. There is a possibility to create a service from any exe via SrvAny, google it. As an alternative to creating your own service, IIS would be a good approach for that. Many solutions bringing foxpro to the web go that route, eg AFP, ActiveVFP, FoxWeb, and many more.

The second possibility is to start a COM server, an OLE class of eg a DLL or an EXE via CREATEOBJECTEX(). You need a COM Server and privileges for such remote executions.

And the third possibility is to use CreateProcessWithLogonW or CreateProcessAsUser via Windows API.

If your question mainly is about an analogon to SQL Server stored procs in foxpro dbc stored procs, then rather forget about it. Foxpro is no client/server database in that sense. There once was http://www.vfpserver.com, but that's gone, nobody used it. While that could help performance for complex queries, you get the overhead to return data to the client somehow, if we talk about sql queries. It's nice to have a fast query running local on the server, but then what do you do with a cursor in a datasession of the server process, you need to turn it into something transportable, eg store it into a seperate dbf file, or turn it to xml to return it as a string, and then the client needs to load this or that into it's cursor.

You have rushmore optimisation and indexes to speed up dbf access to dbfs stored in a lan drive and that works fine for the past two to three decades.

Bye, Olaf.

MikeLewis (Programmer)
8 Aug 12 3:47
You use the xp_cmdshell() function to execute an executable from within T-SQL. You can call it directly from VFP, using SQLEXEC(). Or you can embed it in a stored procedure, and execute that from VFP (by passing an EXEC command to SQLEXEC()).

There are a number of security issues with xp_cmdshell(). Also, it is not enabled by default. The Help topic in Books Online has the relevant information.

If you have any difficulties with the function, you might do better by asking in the "Microsoft SQL Server: Programming" forum here on Tek Tips. (But ask here if you have an issue with SQLEXEC() or other Foxpro-related stuff.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

DSummZZZ (Programmer)
9 Aug 12 18:35
Not a VFP thing, but you may want to check into using something like SysInternals' "PsExec.exe". I won't paste all the links, but a web search will find them.

-Dave Summers-
cheers
Even more Fox stuff at:
http://www.davesummers.net/foxprolinks.htm

craigber (Programmer)
10 Aug 12 10:22
Most DBAs turn off the capability to launch an exe from a stored proc because it's a security issue. It really is a bad idea.

Craig Berntson
MCSD, Visual C# MVP, www.craigberntson.com/blog

MikeLewis (Programmer)
10 Aug 12 10:27

Quote:

Most DBAs turn off the capability to launch an exe from a stored proc because it's a security issue

In the case of SQL Server, I believe it's turned off by default.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close